Bug 293240 - [formatter] 'insert_space_before_opening_brace_in_array_initializer' preference may be reset in certain circumstances
Summary: [formatter] 'insert_space_before_opening_brace_in_array_initializer' preferen...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.6 M3   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-24 13:01 EDT by Frederic Fusier CLA
Modified: 2009-10-27 13:00 EDT (History)
1 user (show)

See Also:


Attachments
Proposed patch (3.47 KB, patch)
2009-10-24 14:55 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frederic Fusier CLA 2009-10-24 13:01:11 EDT
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'...).
Comment 1 Frederic Fusier CLA 2009-10-24 13:18:13 EDT
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...
Comment 2 Frederic Fusier CLA 2009-10-24 14:55:54 EDT
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...
Comment 3 Frederic Fusier CLA 2009-10-24 17:24:41 EDT
Released for 3.6M3 in HEAD stream.
Comment 4 Olivier Thomann CLA 2009-10-27 13:00:38 EDT
Verified for 3.6M3 using I20091027-0100.