Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException: Can not execute Checkstyle #516

Open
jayanthanish opened this issue Apr 10, 2024 · 5 comments
Open

java.lang.IllegalStateException: Can not execute Checkstyle #516

jayanthanish opened this issue Apr 10, 2024 · 5 comments

Comments

@jayanthanish
Copy link

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.

@rnveach
Copy link
Member

rnveach commented Apr 11, 2024

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 .

@jayanthanish
Copy link
Author

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.

@romani
Copy link
Member

romani commented Apr 11, 2024

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

@jayanthanish
Copy link
Author

jayanthanish commented Apr 11, 2024 via email

@romani
Copy link
Member

romani commented Apr 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants