Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 436925 - [formatter]Finally clause indented wrong when if statements are specified and the statement is a try with a comment in the catch
Summary: [formatter]Finally clause indented wrong when if statements are specified and...
Status: CLOSED DUPLICATE of bug 303519
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.5   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-08 10:19 EDT by Palmer Eldritch CLA
Modified: 2015-12-26 15:58 EST (History)
2 users (show)

See Also:


Attachments
formatter preferences export (30.87 KB, text/xml)
2014-06-08 10:19 EDT, Palmer Eldritch CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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 ***