Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 459544 - [formatter] Wrong format of anonymous inner class declaration
Summary: [formatter] Wrong format of anonymous inner class declaration
Status: VERIFIED DUPLICATE of bug 467229
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.6 M5   Edit
Assignee: Mateusz Matela CLA
QA Contact: Manoj N Palat CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-10 07:26 EST by Marius Kleber CLA
Modified: 2016-01-27 04:25 EST (History)
3 users (show)

See Also:


Attachments
Formatter preferences (30.76 KB, text/xml)
2015-02-10 07:26 EST, Marius Kleber CLA
no flags Details
screenshot of the messed up formatting (48.18 KB, image/jpeg)
2015-02-10 07:27 EST, Marius Kleber CLA
no flags Details
test class to reproduce the issue (385 bytes, application/octet-stream)
2015-02-10 07:27 EST, Marius Kleber CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marius Kleber CLA 2015-02-10 07:26:35 EST
Created attachment 250664 [details]
Formatter preferences

Overview Description:
When declaring a member variable of an interface type and implementing that interface as an anonymous inner class at the declaration, the formatting of the following code is messed up. This happens not all the time; It just occurs at every second formatting.
Variant 1: First format messes up
Variant 2: First format is OK, but after adding a new line and formatting again, the source is messed up
The code before the declaration of the anonymous inner class is completely fine.

Steps to Reproduce:
1) Declare a member variable of an interface type
2) Implement the interface as an anonymous inner class at the declaration
3) Format the source code
(If not messed up directly, continue with step 4)
4) Add a new line
5) Format again

Actual Results:
Messed up formatting of code lines following the declaration

Expected Results:
Properly formatted source code

Reproducibility:
Import the attached .java file into eclipse with the attached formatter profile and follow the "steps to reproduce" section

Build Date & Platform Bug Found:
First noticed in Luna 4.4.0 and confirmed to be in Luna 4.4.1 as well

Additional Information:
Does not happen with the built-in Java convention formatter but only with the profile attached, but the behavior of jumping between OK and messed up (see description) made me suspicious. 
The problem itself isn't that grave but, even tough one can ignore whitespaces at compare, comparing with revision from repository doesn't work properly. Also committing wrongly formatted source code into the repository isn't that nice.

Attachments:
formatter.xml - the formatter profiling causing the bug
wrongly_formatted.jpg - an screenshot of the messed up formatting
FormatTest.java - the java test class used to reproduce to bug
Comment 1 Marius Kleber CLA 2015-02-10 07:27:00 EST
Created attachment 250665 [details]
screenshot of the messed up formatting
Comment 2 Marius Kleber CLA 2015-02-10 07:27:27 EST
Created attachment 250666 [details]
test class to reproduce the issue
Comment 3 Marius Kleber CLA 2016-01-12 03:29:53 EST
Bug doesn't occur in Mars 4.5.1 anymore
Comment 4 Jay Arthanareeswaran CLA 2016-01-12 05:25:27 EST
Mateusz, any idea what fixed this?
Comment 5 Mateusz Matela CLA 2016-01-12 16:27:41 EST
(In reply to Jay Arthanareeswaran from comment #4)
> Mateusz, any idea what fixed this?
Well, the bug was there in 4.4 so it looks like it simply no longer occurred after the formatter redesign in 4.5.0.
Comment 6 Marius Kleber CLA 2016-01-13 02:25:20 EST
I just tested with 4.5.0 and the problem occurs there too (same formatter preferences, same workspace) - then again, it doesn't occur in 4.5.1. If you want me to provide further information please let me know.
Comment 7 Mateusz Matela CLA 2016-01-13 16:53:33 EST
(In reply to Marius Kleber from comment #6)

I see an indentation problem with this formatter profile in 4.5.0, but it's not related to anonymous classes or empty lines. It's that everything that should be indented with 2 tabs is indented with 1 tab, because "Indentation size" and "Tab size" are not set to the same value - see bug 467229 and a workaround there.

Let me know if I missed anything else.
Comment 8 Marius Kleber CLA 2016-01-15 02:18:35 EST
(In reply to Mateusz Matela from comment #7)
> (In reply to Marius Kleber from comment #6)
> 
> I see an indentation problem with this formatter profile in 4.5.0, but it's
> not related to anonymous classes or empty lines. It's that everything that
> should be indented with 2 tabs is indented with 1 tab, because "Indentation
> size" and "Tab size" are not set to the same value - see bug 467229 and a
> workaround there.
> 
> Let me know if I missed anything else.

Thanks Mateusz, that works for me! (tested with 4.5.0)

*** This bug has been marked as a duplicate of bug 467229 ***
Comment 9 Dusi Sarath Chandra CLA 2016-01-25 04:40:40 EST
Verified for 4.6 M5 using Version: Neon (4.6)
Build id: I20160119-0800