checkstyle / sonar-checkstyle

Support on Checkstyle in SonarQube. Officially transfered from https://github.com/SonarQubeCommunity/sonar-checkstyle
GNU Lesser General Public License v3.0
171 stars 70 forks source link

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

Open jayanthanish opened 4 months ago

jayanthanish commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

this will help https://github.com/checkstyle/checkstyle/issues/12542 when we get a fix

jayanthanish commented 4 months ago

Hi,

I see that the following has been given as workaround in the link that you provided.

Also, in the initial response you have given the following property to be added:

Can you confirm whether both the solutions work

inorder to skip the checkstyle on my files.

Also let me know where should i add these, I mean under

Which file i need to add?

    ....

On Thu, 11 Apr 2024, 18:51 Roman Ivanov, @.***> wrote:

this will help checkstyle/checkstyle#12542 https://github.com/checkstyle/checkstyle/issues/12542 when we get a fix

— Reply to this email directly, view it on GitHub https://github.com/checkstyle/sonar-checkstyle/issues/516#issuecomment-2049682064, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASBZQTOLUWOBL7WWSICVKETY42E47AVCNFSM6AAAAABGAIFKV2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBZGY4DEMBWGQ . You are receiving this because you authored the thread.Message ID: @.***>

romani commented 4 months ago

workaround is at https://github.com/checkstyle/checkstyle/issues/12542#issuecomment-1366687081 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.