Bug 259443

Summary: [formatter] Blank lines make the code formatting fail
Product: [Eclipse Project] JDT Reporter: Fabrice Tiercelin <fabrice.tiercelin>
Component: CoreAssignee: Frederic Fusier <frederic_fusier>
Status: VERIFIED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, daniel_megert, fabrice.tiercelin, Olivier_Thomann, srikanth_sankaran
Version: 3.4.1   
Target Milestone: 3.6 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Fabrice Tiercelin CLA 2008-12-20 12:17:50 EST
Build ID: M20080911-1700

Formatting this Java code works :
if (true) {
	a = 1;
}
else {
	a = 2;
}

... and you get this :
if (true) {
	a = 1;
} else {
	a = 2;
}

... but formatting that code fails :
if (true) {
	a = 1;
}

else {
	a = 2;
}

... because of the blank line between "}" and "else {"
Comment 1 Dani Megert CLA 2008-12-23 03:07:27 EST
Please attach your formatter settings (export the profile).
Comment 2 Fabrice Tiercelin CLA 2008-12-23 23:13:22 EST
All the settings are the default settings.

Profile : Eclipse [built-in]
Comment 3 Olivier Thomann CLA 2008-12-24 10:09:36 EST
Then provide a test case and describe what you mean by "code formatting fails". Do you get a stack trace?
Comment 4 Fabrice Tiercelin CLA 2008-12-25 05:10:17 EST
I mean :

The code formatting does not work correctly since there is still a blank line between "}" and "else {" whereas the "}" and the "else {" should be on the same line like that :

} else {

In other words, the code formatting is able to correctly format when there is only one newline to remove but is unable to format when there is TWO newlines to remove.

If you want samples, just copy/paste the code I have written in the decription and make a code formatting on it.

Comment 5 Frederic Fusier CLA 2009-01-05 10:29:03 EST
This is due to the fact that the Eclipse built-in formatter settings preserve one blank line (ie. 'Number of empty lines to preserve' preference is equal to '1' in 'Blank lines' tab).

If you change this value to 0, then you'll get the expected output:
if (true) {
        a = 1;
} else {
        a = 2;
}
Comment 6 Frederic Fusier CLA 2009-01-05 10:31:31 EST
So, OK to close as WORKSFORME?
Comment 7 Frederic Fusier CLA 2009-06-23 04:49:30 EDT
(In reply to comment #6)
> So, OK to close as WORKSFORME?
> 
Close as WORKSFORME
Comment 8 Ayushman Jain CLA 2009-08-04 04:47:11 EDT
Verified for 3.6M1 using build I20090802-2000