BoxedBooleanExpressionsCheck - S5411 - ClassCastException

Versions used

  • sonar-maven-plugin:3.7.0.1746
  • SonarCloud

Error observed

[ERROR] Unable to run check class org.sonar.java.checks.BoxedBooleanExpressionsCheck - S5411 on file 'src/main/java/org/simplify4u/jfatek/io/FatekWriter.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.IfStatementTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.ExpressionTree (org.sonar.java.model.statement.IfStatementTreeImpl and org.sonar.plugins.java.api.tree.ExpressionTree are in unnamed module of loader org.sonar.classloader.ClassRealm @7e5e6573)
        at org.sonar.java.checks.BoxedBooleanExpressionsCheck.isFirstUsageANullCheck(BoxedBooleanExpressionsCheck.java:158)
        at org.sonar.java.checks.BoxedBooleanExpressionsCheck.isSafeBooleanExpression(BoxedBooleanExpressionsCheck.java:128)
        at org.sonar.java.checks.BoxedBooleanExpressionsCheck.visitIfStatement(BoxedBooleanExpressionsCheck.java:105)
        at org.sonar.java.model.statement.IfStatementTreeImpl.accept(IfStatementTreeImpl.java:123)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:34)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitBlock(BaseTreeVisitor.java:85)
        at org.sonar.java.model.statement.BlockTreeImpl.accept(BlockTreeImpl.java:75)

The whole analize is ok, only this error is reported during build.

Steps to reproduce

  • Run code analysis. The same error is observed on GitHub Action build and also on local build.
  • Probable error occurs on checking this method:
    public void write(Boolean bool) throws FatekIOException {

        if (bool == null) {
            write("0");
        } else {

            if (bool) {
                write("1");
            } else {
                write("0");
            }
        }
    }

Project

1 Like

Hey there.

Thanks for the great report (a model of what they should look like!). This should be addressed by SONARJAVA-3790 which I imagine will make its way on SonarCloud in the next week or two.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.