checkstyle/sonar-checkstyle

java.lang.IllegalStateException: Can not execute Checkstyle

jayanthanish opened this issue · 5 comments

Sonar version: 9.9.1
Checkstyle sonar plugin version: 10.9.3

I have recently upgraded to this version of sonar and checkstyle check is being executed on my code. In console output it shows an error as follows:
06:48:43 06:48:43.253 ERROR: Error during SonarScanner execution
06:48:43 java.lang.IllegalStateException: Can not execute Checkstyle
06:48:43 at org.sonar.plugins.checkstyle.CheckstyleExecutor.executeWithClassLoader(CheckstyleExecutor.java:113)
......................
06:48:43 Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing xyz.java
......................
06:48:43 Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: IllegalStateException occurred while parsing file xyz.java
.....................
06:48:43 Caused by: java.lang.IllegalStateException: 1:7: no viable alternative at input 'void'
06:48:43 at com.puppycrawl.tools.checkstyle.JavaParser$CheckstyleErrorListener.syntaxError(JavaParser.java:255)
......................
06:48:43 Caused by: org.antlr.v4.runtime.NoViableAltException

Can you please let me know, what this error is about. What are the ways to overcome this and also can you please let me know is it possible to disable or remove these kind of checkstyle checks? If yes, how to do that.

Thank you.

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: IllegalStateException occurred while parsing file xyz.java
Caused by: org.antlr.v4.runtime.NoViableAltException

This is a checkstyle issue, not a sonar checkstyle issue.

Either your Java file is not compilable or it has syntax which Checkstyle doesn't currently support.

If it is not a compile issue, then I recommend checking if Checkstyle has a issue on it. In the meantime, you can exclude the file from processing by using https://checkstyle.org/filefilters/beforeexecutionexclusionfilefilter.html#BeforeExecutionExclusionFileFilter .

Thanks for the information. Can you please let me know where I should add those Filter details to exclude file from processing.
Also, is there any other option to handle it apart from adding a filter. If yes please let me know.

Thank you.

this will help checkstyle/checkstyle#12542 when we get a fix

workaround is at checkstyle/checkstyle#12542 (comment) attention to location of Filter, it should be before TreeWalker.
If you have not way to define exact file to use by Sonar plugin, not a config file generation, order of modules in generated file by sonar is not clear, it might not work.