krasa / EclipseCodeFormatter

IntelliJ plugin - use Eclipse's code formatter directly from IntelliJ. https://plugins.jetbrains.com/plugin/6546
Apache License 2.0
487 stars 117 forks source link

Control-flow exceptions should never be logged #222

Closed mvilliger closed 3 years ago

mvilliger commented 3 years ago

We are getting the following error in IJ 2020.1.2 using EclipseCodeFormatter version 19.5.201.6668.0-Eclipse_2019-09-JavaOnly:

Eclipse Import Optimizer failed

java.lang.Throwable: Control-flow exceptions (like ProcessCanceledException) should never be logged
    at com.intellij.openapi.diagnostic.Logger.checkException(Logger.java:198)
    at com.intellij.idea.IdeaLogger.error(IdeaLogger.java:88)
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:168)
    at krasa.formatter.plugin.EclipseImportOptimizer$1.run(EclipseImportOptimizer.java:65)
    ...
Caused by: com.intellij.openapi.progress.ProcessCanceledException
    at com.intellij.openapi.progress.EmptyProgressIndicator.checkCanceled(EmptyProgressIndicator.java:84)
    at com.intellij.openapi.progress.impl.CoreProgressManager.doCheckCanceled(CoreProgressManager.java:124)
    at com.intellij.openapi.progress.ProgressManager.checkCanceled(ProgressManager.java:225)
    at com.intellij.openapi.progress.ProgressIndicatorProvider.checkCanceled(ProgressIndicatorProvider.java:49)
    at com.intellij.psi.impl.source.tree.CompositeElement.getPsi(CompositeElement.java:687)
    at com.intellij.psi.impl.source.SourceTreeToPsiMap.treeElementToPsi(SourceTreeToPsiMap.java:30)
    at com.intellij.psi.impl.source.PsiJavaFileBaseImpl.getImportList(PsiJavaFileBaseImpl.java:154)
    at krasa.formatter.plugin.EclipseImportOptimizer.optimizeImportsByEclipse(EclipseImportOptimizer.java:88)
    at krasa.formatter.plugin.EclipseImportOptimizer.access$100(EclipseImportOptimizer.java:24)
    at krasa.formatter.plugin.EclipseImportOptimizer$1.run(EclipseImportOptimizer.java:54)
    ... 19 more

See com.intellij.openapi.diagnostic.ControlFlowException for details. So maybe add an instanceof check to the catch (Exception e) block rethrowing the exception instead of logging it?

krasa commented 3 years ago

Fixed, thanks!

mvilliger commented 3 years ago

Thank you very much for the fast fix! Please note that several throwables are ControlFlowExceptions. Not only ProcessCanceledException.

krasa commented 3 years ago

Yes, but it should be fine. :-)

mvilliger commented 3 years ago

Ok, fine with me. Thanks a lot! :)