Community
Participate
Working Groups
While testing patch for bug 286601 and running formatter massive tests on a Galileo full source workspace, I discovered that in certain circumstances, the formatter preferences insert_space_before_opening_brace_in_array_initializer may be reset (ie. set to false although formatter profile was initially set to true). This is a consequence of fix for bug 267551 where this preference was temporarily disabled while traversing an annotation. I simply stupidly forgot to protect the traversal with a 'finally' as typically a AlignmentException can occur there! Set as major because when this happen, the formatter will never work as the user would expect after having set his or her profile (e.g. the Eclipse built-in profile set this preference to 'true'...).
Here is a test case extracted from the Galileo full source workspace: public class Test { public static <A, B> Function<A, B> forMap( Map<? super A, ? extends B> map, @Nullable final B defaultValue) { if (defaultValue == null) { return forMap(map); } return new ForMapWithDefault<A, B>(map, defaultValue); } public Object[] bar() { return new Object[] { null }; } } Using the Eclipse built-in profile + space only, the formatter output is: public class Test { public static <A, B> Function<A, B> forMap(Map<? super A, ? extends B> map, @Nullable final B defaultValue) { if (defaultValue == null) { return forMap(map); } return new ForMapWithDefault<A, B>(map, defaultValue); } public Object[] bar() { return new Object[]{ null }; } } Note that there's no longer space before the opening brace in the array initializer of the method bar return although the profile says that one should be added...
Created attachment 150445 [details] Proposed patch Add a finally to be sure to revert the preference value whatever happens during the annotation traversal. Note that I downsized the severity as the preference reset disappeared as soon as another code formatter instance is used. Hence, when formatting two different compilation unit, if it's reset on the first one, it's reinitialized correctly for the second one. So, it is only noticeable for specific CU or for long formatting operation when the same instance of code formatter is reused which is not a common use case...
Released for 3.6M3 in HEAD stream.
Verified for 3.6M3 using I20091027-0100.