Community
Participate
Working Groups
If the code formatter option "Insert a new line before an opening brace" is enabled, this bug appears. (For the sake of this example, assume the "Insert a new line inside an empty block" option is also enabled, but it's not relevant to the bug.) Here is an example block of code, properly formatted: abstract class Foo { void foo1() { } abstract void foo2() throws Exception; void foo3() { } } However, "Source->Format" adds an unwanted blank line to this code: abstract class Foo { void foo1() { } abstract void foo2() throws Exception; void foo3() { } } If the "throws Exception" clause is removed from foo2() above, the formatter does not add the unwanted blank line. This bug only seems to affect method definitions which follow abstract method declarations where the abstract method throws an exception.
This is addressed in the new formatter. Fixed and released in HEAD. Regression test added.
Verified.
This bug was filed against version 2.1, but it also exists in version 3.0M6, with exactly the same broken behavior -- even though this bug WAS previously fixed. If a regression test was added, why didn't it catch this regression?
Created attachment 7588 [details] Screen shot to set the new formatter Are you using the new formatter? The old formatter won't be fixed. The fix is in the new formatter. So if you switch to the new formatter, it should work as expected. I checked it using a M6 build. See the screen shot to see how to use the new formatter. Close as fixed in the 3.0 stream.
Close as FIXED.
No, I wasn't using the new formatter. I had no idea that "new formatter" was a different mode entirely -- I assumed it meant just a newer version of the code. It's strange, though -- I seem to recall testing (with the old formatter) and seeing that the bug was fixed. Or maybe I'm misremembering -- it seems to be broken on the 3.0 milestone from August 28 I was using before today... Anyway, the new formatter does not appear to be adding these unwanted blank lines, although it doesn't remove them if they're already there (say, from a previous auto-format from the old formatter) -- is this a bug?
You have to check the value of the number of blank lines to preserve. In your case, you want zero. See the code formatter preference page. You can define your own settings.
If I understand that setting correctly, it won't do what I want. If a blank line appears in the middle of the declaration like this bug created under the old formatter, I would want the formatter to remove that blank line. Similarly, if there are blank lines in the middle of a statement being formatted that wouldn't normally be there, I'd want those removed too. However, I want to keep blank lines (or at least one) between statements, since I regularly group statements by strategic use of blank lines in the code. It seems that I can't do both at the same time. If I set the number of lines to preserve to zero, won't it remove all my carefully-placed blank lines between groups of statements?
You are right. There is no way to have both. In your case, get rid of your extra line and it won't be added again when you format your code.
Would it be feasible to add an option for the number of blank lines to preserve between statements? There's already a lot of fine-grained control, so why not?