SonarQube analysis for Android project with Java 11

We use SoanrQube 8.9 LTS for our Android(Java+Kotlin) projects. We have recently upgraded projects’ codebase to compile them with JDK 11.

The gradle project structure is like this:

  • RootProject
    |
    |----> :app (compiled using JavaVersion.VERSION_11, code coverage disabled)
    |
    |----> :module1 (compiled using JavaVersion.VERSION_11 and code coverage enabled)
    |
    |----> :module2 (excluded from scan - it is aar file imported as module, compiled in Java 8)
    |
    |----> :module3 (compiled using JavaVersion.VERSION_11, code coverage disabled)

We noticed that while running the sonar analysis on Azure Pipelines with latest sonar extension tasks, we started getting unwanted errors internally in the scan task, such as:

  1. [org.sonarqube.gradle.SonarQubeTask] Unable to run check class org.sonar.java.se.SymbolicExecutionVisitor - on file ‘module1/SourceFile1.java’, To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/
    org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(1462) Type java.lang.String is indirectly referenced from required .class files but cannot be resolved since the declaring package java.lang exported from module java.base conflicts with a package accessible from module
    at org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:162)
  2. [ERROR] [org.sonarqube.gradle.SonarQubeTask] Unable to run check class org.sonar.java.checks.unused.UnusedPrivateMethodCheck - S1144 on file ‘module1/SomeFile.java’, To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/
    java.lang.IllegalArgumentException: 128 is not a valid line for pointer. File module1/SomeSourceFile1.java has 10 line(s)
  3. [ERROR] [org.sonarqube.gradle.SonarQubeTask] Unable to run check class org.sonar.java.checks.unused.UnusedPrivateMethodCheck - S1144 on file ‘module1/SomeSourceFile2.java’, To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/
    java.lang.IllegalArgumentException: 128 is not a valid line for pointer. File module1/SomeSourceFile2.java has 22 line(s)
  4. [DEBUG] [org.sonarqube.gradle.SonarQubeTask] ‘module1/SomeTest.java’ generated metadata as test with charset ‘UTF-8’
    [ERROR] [org.sonarqube.gradle.SonarQubeTask] ECJ Unable to resolve type junit.framework.TestCase
    org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
  5. [ERROR] [system.err] Status ERROR: org.eclipse.jdt.core code=4 Could not retrieve declared methods org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
    [ERROR] [system.err] Status ERROR: org.eclipse.jdt.core code=4 Could not retrieve interfaces org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
    [ERROR] [system.err] Status ERROR: org.eclipse.jdt.core code=4 Could not retrieve interfaces org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
    [ERROR] [system.err] Status ERROR: org.eclipse.jdt.core code=4 Could not retrieve declared methods org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

These errors are silent – the gradle sonarqube task in the pipeline does not fail, rather just keeps reporting the long exception stacktraces in the console log.

When we observed the :sonarqube task’s execution info with --debug flag, we noticed that the sonar.java.test.libraries is being set as :
sonar_java_test_libraries.txt (17.7 KB),
and sonar.java.libraries as :
sonar_java_libraries.txt (14.7 KB)

Before reporting this issue here, we searched for similar issues as such, but they relate to Java-Affinity jar dependency, which we do not use in our Android project. We also followed Moving analysis to Java 11, but as pointed out in this doc, we use Gradle sonar scanned plugin in Azure Devops pipeline, so it internally takes care of setting appropriate JAVA_HOME and sonar.java.jdkHome property for the analysis.

The side-effects of these unwanted exceptions are:

  1. Code coverage for module1 is reset to 0.0% as opposed to ~70% when it was being compiled with JDK 8.
  2. PR decoration in Azure, gets random issues as comments. The issue commented is not even relevant to the source file shown in the comment.
  3. The source files in which these exceptions occurred are not scanned at all

Please kindly help us resolving this problem.
Thank you!

1 Like

Could anyone take a look at these bugs please? We are still facing the issue.
Thanks.