revelc/formatter-maven-plugin

Mockito WHEN Bug in Eclipse formatting jdt core 3.32.0 and 3.33.0

Closed this issue · 3 comments

Expect some vague stuff here. Spent hours looking at this and while I'm probably onto something this would likely go entirely unnoticed by many.

Not sure if edge case or what yet. Basically 3.31.0 with this plugin at latest main works fine in tabs to spaces. But setting it to 3.32.0 or 3.33.0 partially does but doesn't touch some tabs and simply commenting calls out can make it work. Not seeing why exactly but wanted to document this. The issue is present in Eclipse itself so not this plugin. Technically we could fix by supporting tabs to spaces and size of the spacing directly but prefer eclipse work...

What I can confirm is that 3.31.0 came from this commit c629d6bbecf94f42dbc352301f30a47d6578c4e9 and our direct support was 2.21.0 which works fine.

Can find that here in full history https://github.com/eclipse-jdt/eclipse.jdt.core/commits/master?after=b1c0332929b1dbf651f62c7792a6d16d4137e768+139&branch=master&qualified_name=refs%2Fheads%2Fmaster.

Believe issue is from this eclipse-jdt/eclipse.jdt.core@ebc978e

The example I can cause this with is mockito 'when'. But some work without issue. I can add junk on front of the 'when' such as 'junkwhen' or even comment it out then it formats both by our plugin and eclipse. I don't really understand yet why some work and others do not.

The issue is due to usage of static import on mockito 'when'. The "Handle 'when' clause in switch pattern expressions" eclipse-jdt/eclipse.jdt.core@ebc978e that I noted earlier is the issue. I do not know if they fixed it but any fix requires we move to jdk 17. So it would be best to drop back actually.

Issue is already reported eclipse-jdt/eclipse.jdt.core#609

Closing as this was resolved.