Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 436925

Summary: [formatter]Finally clause indented wrong when if statements are specified and the statement is a try with a comment in the catch
Product: [Eclipse Project] JDT Reporter: Palmer Eldritch <the.ubik>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: manoj.palat, mateusz.matela
Version: 4.4   
Target Milestone: 4.5   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
formatter preferences export none

Description Palmer Eldritch CLA 2014-06-08 10:19:25 EDT
Created attachment 244068 [details]
formatter preferences export

Copy paste this in a file project (the formatting is correct):

package snippet;

public class Snippet {

	void meth() {
		try {} finally {
			if (true) try {} catch (Exception e) {
				try {} catch (Exception e2) {
					// If you omit this comment all fine
			}
			} finally {
				System.out.println("This finally block is indented wrongly");
			}
		}
	}
}


Hit Ctrl+Shift+F and get:

package snippet;

public class Snippet {

	void meth() {
		try {} finally {
			if (true) try {} catch (Exception e) {
				try {} catch (Exception e2) {
					// If you omit this comment all fine
			}
		} finally {
			System.out.println("This finally block is indented wrongly");
		} // notice this
		}
	}
}


That can be _very_ confusing in situations with nested try/finally (of course this a contrived example)
If you omit the comment all is fine.

I have previously filled some bugs with the comments handling - _there is definitely something fishy there_ - please have a look:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=422870
https://bugs.eclipse.org/bugs/show_bug.cgi?id=421748
https://bugs.eclipse.org/bugs/show_bug.cgi?id=419909
https://bugs.eclipse.org/bugs/show_bug.cgi?id=396686

I attach my formatting prefs
Comment 1 Mateusz Matela CLA 2015-12-26 15:58:12 EST
This problem no longer occurs after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***