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

[PRIORITY HIGH] Crash SonarQube analysis #42

Closed
dedece35 opened this issue Jan 10, 2023 · 2 comments
Closed

[PRIORITY HIGH] Crash SonarQube analysis #42

dedece35 opened this issue Jan 10, 2023 · 2 comments
Assignees
Labels
java 💉 bug Something isn't working

Comments

@dedece35
Copy link
Member

dedece35 commented Jan 10, 2023

Describe the bug
when we launch a SonarQube analysis, there is a lot of exception on ecocode plugin. Then, the analysis crashes and this stops and CI/CD pipeline.
please see examples above.

To Reproduce
JDK 17
Gradle
example command launched : gradle --no-daemon sonarqube -Dsonar.qualitygate.wait=true -Dsonar.branch.name=release-4.1 -Pspring.test.config=/builds/contenu/rcc/rcc/.gradle/test.properties
@dedece35 can give some example source code if need (to test it)

Expected behavior
Analysis in succes without exceptions.
Once correction OK, upgrade (if possible) SonarQube checks in code to avoid this kind of issue (make an audit of each rule to check Class Casts).

Screenshots
Please see log file.

Software Versions

  • SonarQube Version: 9.8 (build 63668)
  • Plugin Version: 0.2.1
  • JDK version : 17
@dedece35 dedece35 added 💉 bug Something isn't working java labels Jan 10, 2023
@dedece35 dedece35 self-assigned this Jan 10, 2023
@dedece35
Copy link
Member Author

Exception 1 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/service/filterchain/siret/SiretOrigineLienFilter.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.ForEachStatementImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.ForEachStatementImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 2 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/comptemanager/gateway/handlers/AbstractCommandHandler.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.ForEachStatementImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.ForEachStatementImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 3 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/checker/horaireexceptionnel/HoraireExceptionnelValidationChecker.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.WhileStatementTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.WhileStatementTreeImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 4 :
Unable to run check class fr.cnumr.java.checks.UnnecessarilyAssignValuesToVariables - S63 on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/script/horaireexceptionnel/HoraireExceptionnelMigrationService.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "org.sonar.plugins.java.api.tree.ReturnStatementTree.expression()" is null at fr.cnumr.java.checks.UnnecessarilyAssignValuesToVariables$CheckUseVariableVisitor.visitReturnStatement(UnnecessarilyAssignValuesToVariables.java:152) at org.sonar.java.model.statement.ReturnStatementTreeImpl.accept(ReturnStatementTreeImpl.java:70) at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)

Exception 5 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/service/notification/MessageNotificationFactory.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.ForEachStatementImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.ForEachStatementImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 6 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/comparator/ClassSpecificityComparator.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.WhileStatementTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.WhileStatementTreeImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 7 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/alim/factory/QualibatFactory.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.ForEachStatementImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.ForEachStatementImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 8 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/service/liencontenu/LienContenuService.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.WhileStatementTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.WhileStatementTreeImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 9 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/security/AzureSsoAuthenticationProvider.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.ForEachStatementImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.ForEachStatementImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 10 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/checker/intitule/IntituleNormalizationChecker.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.WhileStatementTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.WhileStatementTreeImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 11 :
Unable to run check class fr.cnumr.java.checks.UnnecessarilyAssignValuesToVariables - S63 on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/comptemanager/callback/LienContenuCreationCallback.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "org.sonar.plugins.java.api.tree.ReturnStatementTree.expression()" is null at fr.cnumr.java.checks.UnnecessarilyAssignValuesToVariables$CheckUseVariableVisitor.visitReturnStatement(UnnecessarilyAssignValuesToVariables.java:152) at org.sonar.java.model.statement.ReturnStatementTreeImpl.accept(ReturnStatementTreeImpl.java:70) at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40) at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:34)

Exception 12 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/comptemanager/callback/UniqueContenuCallback.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.ForEachStatementImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.ForEachStatementImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 13 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/service/persistence/PersistenceService.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.WhileStatementTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.WhileStatementTreeImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 14 :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/service/search/provider/AbstractSearchProvider.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.ForEachStatementImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.ForEachStatementImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

Exception 15 (L2742) :
Unable to run check class fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop - GSCIL on file 'solocal-rcc-server/src/main/java/com/solocal/rcc/listener/IndexingListener.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/ java.lang.ClassCastException: class org.sonar.java.model.statement.WhileStatementTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.ForStatementTree (org.sonar.java.model.statement.WhileStatementTreeImpl and org.sonar.plugins.java.api.tree.ForStatementTree are in unnamed module of loader org.sonar.classloader.ClassRealm @6e29edfd) at fr.cnumr.java.checks.AvoidGettingSizeCollectionInLoop.visitNode(AvoidGettingSizeCollectionInLoop.java:36) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452) at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468) at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)

@dedece35
Copy link
Member Author

dedece35 commented Jan 12, 2023

ANALYSIS
13 of these 15 exceptions are consequence of a lack in code : rule AvoidGettingSizeCollectionInLoop is enabled for "foreach", "for" and "while" loops, but in the code only "for" loops are managed (with casting process). Thus, if a "while" loop or "foreach" loop appears, a casting exception is launched.

CORRECTION
2 kind of exception :

  • ClassCastException :
    • add "while" loop management
    • disable "foreach" loop because it's impossible to use code in condition loop (the foreach loop syntax is very strict), thus foreach loop is useless for this rule
  • NullPointerException :
    • add checks to avoid NPE
  • global modifications :
    • improve existing unit tests
    • add new unit tests
    • complete audit issue Audit of implemented rules #34 to check existing implemented rules regarding this implementation error

corrections on PR #45
waiting for reviewing by @jhertout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java 💉 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant