Java code formatting not working properly
Answered
Hey there!
I'm using IntelliJ since a few days. Everything is really nice so far except one thing that annoys me really!
I've setup the code formatters according to my wishes (hell, there's a lot one can define), but it doesn't work as expected.
I configured that, braces are set within my annotation parenthes (as you can see in the screenshot below).
Well this will sometimes work, but mostly not.
My code is formatted as below:
@Configuration @ComponentScan(basePackages = "mycompany.myapp", useDefaultFilters = true) @PropertySource("classpath:app.properties") public class WebMvcConfiguration extends WebMvcConfigurationSupport { }
Point is, if I copy my code, then remove everything and paste it again. Formatting is fine then (at least for some time).
My log shows this error:
2014-02-19 10:16:42,781 [2204900] ERROR - llij.ide.plugins.PluginManager - null java.lang.NullPointerException at com.intellij.formatting.FormatterTagHandler.getFormatterTag(FormatterTagHandler.java:51) at com.intellij.formatting.InitialInfoBuilder.b(InitialInfoBuilder.java:293) at com.intellij.formatting.InitialInfoBuilder.a(InitialInfoBuilder.java:273) at com.intellij.formatting.InitialInfoBuilder.a(InitialInfoBuilder.java:173) at com.intellij.formatting.InitialInfoBuilder.a(InitialInfoBuilder.java:235) at com.intellij.formatting.InitialInfoBuilder.iteration(InitialInfoBuilder.java:109) at com.intellij.formatting.FormatProcessor$WrapBlocksState.doIteration(FormatProcessor.java:1313) at com.intellij.formatting.FormatProcessor$State.iteration(FormatProcessor.java:1246) at com.intellij.formatting.FormatProcessor.iteration(FormatProcessor.java:244) at com.intellij.formatting.FormatterImpl.a(FormatterImpl.java:434) at com.intellij.formatting.FormatterImpl.adjustLineIndent(FormatterImpl.java:371) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl$5.doPerform(CodeStyleManagerImpl.java:329) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl$5.doPerform(CodeStyleManagerImpl.java:326) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerRunnable.perform(CodeStyleManagerRunnable.java:112) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.a(CodeStyleManagerImpl.java:326) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.access$500(CodeStyleManagerImpl.java:59) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl$3.compute(CodeStyleManagerImpl.java:289) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl$3.compute(CodeStyleManagerImpl.java:286) at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:113) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.adjustLineIndent(CodeStyleManagerImpl.java:286) at com.intellij.codeInsight.editorActions.EnterHandler$DoEnterAction.run(EnterHandler.java:422) at com.intellij.codeInsight.editorActions.EnterHandler.a(EnterHandler.java:169) at com.intellij.codeInsight.editorActions.EnterHandler.access$000(EnterHandler.java:53) at com.intellij.codeInsight.editorActions.EnterHandler$1.run(EnterHandler.java:74) at com.intellij.psi.impl.source.PostprocessReformattingAspect$2.compute(PostprocessReformattingAspect.java:104) at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:113) at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:101) at com.intellij.codeInsight.editorActions.EnterHandler.executeWriteAction(EnterHandler.java:71) at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$1.run(EditorWriteActionHandler.java:55) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:981) at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler.execute(EditorWriteActionHandler.java:38) at com.intellij.codeInsight.template.impl.editorActions.EnterHandler.executeWriteAction(EnterHandler.java:51) at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$1.run(EditorWriteActionHandler.java:55) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:981) at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler.execute(EditorWriteActionHandler.java:38) at com.intellij.openapi.editor.actionSystem.EditorAction$1.run(EditorAction.java:82) at com.intellij.openapi.command.impl.CommandProcessorImpl.executeCommand(CommandProcessorImpl.java:124) at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:93) at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:67) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$3.performAction(IdeKeyEventDispatcher.java:564) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:611) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.d(IdeKeyEventDispatcher.java:463) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:206) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:493) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:335) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 2014-02-19 10:16:42,781 [2204900] ERROR - llij.ide.plugins.PluginManager - IntelliJ IDEA 13.0.2 Build #IU-133.696 2014-02-19 10:16:42,781 [2204900] ERROR - llij.ide.plugins.PluginManager - JDK: 1.6.0_65 2014-02-19 10:16:42,781 [2204900] ERROR - llij.ide.plugins.PluginManager - VM: Java HotSpot(TM) 64-Bit Server VM 2014-02-19 10:16:42,781 [2204900] ERROR - llij.ide.plugins.PluginManager - Vendor: Apple Inc. 2014-02-19 10:16:42,781 [2204900] ERROR - llij.ide.plugins.PluginManager - OS: Mac OS X 2014-02-19 10:16:42,782 [2204901] ERROR - llij.ide.plugins.PluginManager - Last Action: EditorEnter
Please sign in to leave a comment.
It's likely this issue: IDEA-119684 "Code Style/Spaces/Within/AnnotationParentheses" behaves erratically" although we haven't been able to reproduce it yet.
The error in the log is related to formatter control markers (it's just a bug). You can disable them in Settings|Code Style|General|Formatter Control by unchecking "Enable formatter markers in comments". I'm not sure it has anything to do with spaces problem but you can give it a try.
Unfortunately, disabling formatting markers in comments does not help.
Is there any chance that it will be fixed sooner?
It's pretty strange that I works perfect after I removed the source code and pasted it again (without any changes)..
It may take some time because we still can't reproduce the issue. If it's a specific combination of options (just a guess), you could probably help by attaching your settings to the bug report above (File|Export Settings|Code Style Schemes).
I hope it's okay if I attach it here. I'll be honest, I have no idea how to attach it to the Issue ?:|
Attachment(s):
settings.jar
No problem. I have attached your code style settings to the issue. We'll try to reproduce the issue and find what's causing it. Thanks!
well, 8 years after thisissue was reported, I have the same issue. Using IntelliJ IDEA 2022.2.1 (Ultimate Edition), when formatting didn't work automatically, i tried getting google style plugin also. Also checked all the stuff mentioned here. Still formatting is not working for me. Seems like an issue with IDE? Could you please check and reply me back on my email. I am currently in trial version of Ultimate, have been thinking of purchasing the license but if formatting does not work... then .....
Received this exception trace after some minutes:
Er Rahulverma
What is the problem that you are having exactly?
Could you provide a code sample for which formatting doesn't work and describe what you do step by step and what happens/doesn't happen?
The error from your second post seems to be coming from the google-formatter plugin. Please disable it for the time being, and restart the IDE afterwards.