After upgrading SonarJava plugin to 5.8 (15699) Sonar can't analyze class anymore (guava issue)

I’m using

  • SonarQube 6.7.5.38563
  • Maven Sonar Plugin 3.5.0.1254

With plugin SonarJava 5.7 (build 15470) the analysis works well.
After upgrading to SonarJava plugin 5.8 (15699) I got the error:

SonarQube is unable to analyze file

Caused by: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.che
ckNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Obje
ct;

Hello Marco,

Can you share the full analysis logs (full maven logs in your case) and more details about the project you are scanning: which version of Java is used to compile this project, the pom.xml?

The best would be to share a reproducer so we can quickly reproduce the problem on our side. Is that something you can provide?

Thanks

Hi Alexandre, the project is private for my client so not easily shareble.

Anyway …some additional info:

<!-- Maven Enforcer Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce-maven</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>[2.2.1,)</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <message>Project must be compiled with Java 8 or higher</message>
                                    <version>1.8.0</version>
                                </requireJavaVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Maven Compiler Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

Marco

Hello,

Which com.google.guava:guava version are you using in your pom.xml?

Thanks

I have this dependency org.mock-server:mockserver-netty:jar:5.3.0 that has guava as dependency com.google.guava:guava:jar:18.0

Thanks

Same issue here:

  • Built with JDK 10.0.1 using Gradle 4.10.2
  • The project has a dependency on Guava 26.0-jre
  • The problem disappears as soon as I revert to SonarJava 5.7

The stacktrace ends with:

Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at com.sonar.sslr.impl.typed.ReflectionUtils.invokeMethod(ReflectionUtils.java:34)
	... 124 more
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
	at org.sonar.java.model.KindMaps.getAssignmentOperator(KindMaps.java:131)
	at org.sonar.java.ast.parser.TreeFactory.newElementValuePair(TreeFactory.java:787)
	... 128 more

I don’t think it has anything to do with the version of Guava in the project being scanned, it seems more like a classpath conflict between the dependencies of SonarJava and the Maven and Gradle plugins. SonarJava 5.7 is bundled with Guava 19.0 whereas 5.8 is bundled with 26.0-jre, based on the content of META-INF/maven/com.google.guava/guava/pom.xml. KindMaps.getAssignmentOperator() was compiled to call Preconditions.checkNotNull(Object, String, Object) in 5.8, which is indeed one of the signatures of checkNotNull() in Guava 26.0-jre. In 5.7, it called Preconditions.checkNotNull(Object, String, Object[]), which was one of the only 3 signatures of the method in Guava 19.0. Since we get an exception, obviously the version of Preconditions first found in the classpath does not have the new signature.

Hi folks,

That look like a really strange issue. We did tests of SonarJava 5.8, using JDK 10.0.1 and various versions of SonarQube. Everything works fine. So there should be something special in your setup.

FYI, SonarQube plugins are executed in an isolated classloader. It means dependencies of your project, or even Maven/Gradle own dependencies are not supposed to be visible to classes of SonarJava.

Are you using any special flag of the JDK 10 to compile your projects?

Do you have any custom plugin on your instance, extending rules of SonarJava?

Also, you can try to run something like:

export MAVEN_OPTS=-verbose:class
mvn sonar:sonar | grep com.google.common.base.Preconditions

For comparison, on my box it gives:

[0,267s][info][class,load] com.google.common.base.Preconditions source: file:/home/julien/Prog/Softs/apache-maven-3.5.2/lib/guava-20.0.jar
[2,562s][info][class,load] com.google.common.base.Preconditions source: file:/home/julien/.sonar/cache/4d51abc8c7a7796c4c6d163561d3aaf8/sonar-scanner-engine-shaded-6.7.5.jar
[3,338s][info][class,load] com.google.common.base.Preconditions source: file:/home/julien/.sonar/cache/dc952bf163f53f86e58138171c4392b5/sonar-java-plugin-5.8.0.15699.jar
[6,820s][info][class,load] com.google.common.base.Preconditions source: file:/home/julien/.sonar/cache/c5070f78f25283e530b64cf2971675a1/sonar-python-plugin-1.8.0.1496.jar
[6,906s][info][class,load] com.google.common.base.Preconditions source: file:/home/julien/.sonar/cache/00fc9c47c69bf98ddae9f9cd8a3d75b3/java-custom-rules-1.0-SNAPSHOT.jar_unzi
p/META-INF/lib/guava-19.0.jar
[6,941s][info][class,load] com.google.common.base.Preconditions source: file:/home/julien/.sonar/cache/8aa2bdaa868a414c07e56c973c0e5399/sonar-flex-plugin-2.3.jar
[7,071s][info][class,load] com.google.common.base.Preconditions source: file:/home/julien/.sonar/cache/42606bbcf26b849ceb15e8b5fb476be5/sonar-php-plugin-2.11.0.2485.jar
[7,159s][info][class,load] com.google.common.base.Preconditions source: file:/home/julien/.sonar/cache/3c43ca34b48e025530485308ddac54a2/sonar-javascript-plugin-3.2.0.5506.jar

I forgot to mention that I’m on SonarQube 7.3, though it probably has no impact on this. No special flags for the JDK 10 build.

Here are the installed plugins that contain com.google.common.base.Preconditions, in addition to SonarJava:

  • sonar-html-plugin-3.0.1.1444.jar, which uses Guava 15.0
  • sonar-javascript-plugin-5.0.0.6962.jar, which uses Guava 19.0

Are the plugins actually isolated from each other? If not, SonarHTML will be loaded before SonarJava and we have the answer. Then, if all the installed plugins don’t have compatible versions of Guava, there will be failures one way or another.

It’s difficult to reproduce the problem now, as SonarQube is used by all our builds and I can’t really leave 5.8 installed if it fails.

I also don’t think the version of SonarQube make a difference, since we haven’t changed plugin classloading recently.

Are the plugins actually isolated from each other?

Yes, they are.

I did my best to reproduce the issue, but I wasn’t able. So may I ask people on this thread to help me to narrow down the issue?

We already know:

  • the problem appear when upgrading to SonarJava 5.8, which embed Guava 26
  • it happens with various runtime JDK (@marcore seems to use 1.8, @fpavageau uses 10.0.1)
  • that it can happens with Maven (@marcore) or Gradle (@fpavageau) scanners
  • seems unrelated to the fact the analyzed project has a compile dependency on Guava < 26
  • seems unrelated to the version of SQ

Things to explore:

  • is the problem happening for every Java projects (even small ones) or only for some specific source code?
  • can you remove all plugins (on a test instance) but SonarJava, and still reproduce the issue?

Thanks

Since we run SonarQube in Docker, I was able to reproduce the problem locally. And then I spent quite some time trying to figure out which combination of plugins produced the error, by only using SonarJava and one of the other plugins, but it never happened until I added all the plugins back. So I tried the other way around, only removing one plugin from our set, but the error never happened either!

So I have an environment reproducing the problem, but it only happens with our exact set of plugins! Next, I’m going to try and create a project as simple as possible to reproduce the problem and push it to GitHub. Had I known I would not reproduce the error in any modified environment, I would have done that first, because the project I tested with takes a bit more than 2 minutes to build…

For the record, I tried the build with -verbose:class, and only got

[0.719s][info][class,load] com.google.common.base.Preconditions source: file:/Users/fpavageau/.gradle/wrapper/dists/gradle-4.10.2-all/9fahxiiecdb76a5g3aw9oi8rv/gradle-4.10.2/lib/guava-jdk5-17.0.jar
[15.963s][info][class,load  ] com.google.common.base.Preconditions source: file:/Users/fpavageau/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/26.0-jre/6a806eff209f36f635f943e16d97491f00f6bfab/guava-26.0-jre.jar
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;

The first match seems to be the Gradle Wrapper, and the second one is our integration tests, running in a forked JVM.

1 Like

Here you go: https://github.com/fpavageau/sonar-java-guava-conflict.

It includes the build instruction to create the Docker image for SonarQube with the same plugins we have installed, and an “application” consisting of a single class with an empty main() and no dependencies at all.

Yet, on my machine, it always fails with

> Task :sonarqube FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sonarqube'.
> SonarQube is unable to analyze file : '/Users/fpavageau/devs/oss/sonar-java-guava-conflict/src/main/java/com/ekino/Application.java'

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':sonarqube'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
        at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.sonar.java.AnalysisException: SonarQube is unable to analyze file : '/Users/fpavageau/devs/oss/sonar-java-guava-conflict/src/main/java/com/ekino/Application.java'
        at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:105)
        at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:68)
        at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:116)
        at org.sonar.java.JavaSquid.scan(JavaSquid.java:110)
        at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:93)
        at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:45)
        at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:88)
        at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:62)
        at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:74)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:166)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:300)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:295)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:269)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
        at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:82)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:131)
        at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
        at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:111)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy57.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
        at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
        at org.sonarqube.gradle.SonarQubeTask.run(SonarQubeTask.java:99)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:801)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:768)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
        ... 31 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.sonar.sslr.impl.typed.ReflectionUtils.invokeMethod(ReflectionUtils.java:36)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:110)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:95)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:101)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visitNonTerminal(SyntaxTreeCreator.java:85)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.visit(SyntaxTreeCreator.java:66)
        at com.sonar.sslr.impl.typed.SyntaxTreeCreator.create(SyntaxTreeCreator.java:61)
        at com.sonar.sslr.api.typed.ActionParser.parse(ActionParser.java:111)
        at com.sonar.sslr.api.typed.ActionParser.parse(ActionParser.java:97)
        at org.sonar.java.ast.parser.JavaParser.parse(JavaParser.java:55)
        at org.sonar.java.ast.parser.JavaParser.parse(JavaParser.java:32)
        at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:94)
        ... 80 more
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at com.sonar.sslr.impl.typed.ReflectionUtils.invokeMethod(ReflectionUtils.java:34)
        ... 180 more
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
        at org.sonar.java.model.KindMaps.getLiteral(KindMaps.java:135)
        at org.sonar.java.ast.parser.TreeFactory.literal(TreeFactory.java:140)
        ... 184 more

Tested with the following JDKs:

  • OpenJDK 10
    $ java -version
    openjdk version "10" 2018-03-20
    OpenJDK Runtime Environment 18.3 (build 10+46)
    OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
    
  • Zulu OpenJDK 10.0.1
    $ java -version
    openjdk version "10.0.1" 2018-04-17
    OpenJDK Runtime Environment Zulu10.2+3 (build 10.0.1+9)
    OpenJDK 64-Bit Server VM Zulu10.2+3 (build 10.0.1+9, mixed mode)
    
  • Oracle JDK 10.0.1
    $ java -version
    java version "10.0.1" 2018-04-17
    Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
    Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
    

It builds and analyses fine with JDK 8 if you comment out the sourceCompatibility and targetCompatibility in build.gradle, though.

Hi Frank,

Thanks for the nice reproducer. I was able to see the error. I will investigate today and keep you posted.

++

To me, the problem come from the plugin AEM-Rules-for-SonarQube
This plugin adds custom rules to SonarJava, but wrongly declare SonarJava as its “base” plugin.

The concept of “base” plugin was used long time ago when we used to split functional plugin into multiple technical plugins (aka ecosystem). In the end all plugins declaring the same “base” are loaded in the same classloader.

AEM plugin is embedding Guava 19, and so is conflicting with Guava in SonarJava. Removing the “basePlugin” attribute should fix the issue, since the two plugins will have their own classloader.

A plugin providing custom rules doesn’t need to declare a base plugin.

1 Like

Thanks for the quick analysis. I now realize that the OP also uses AEM and obviously has the same plugin installed.

The issue was reported before I got there, so I added a link to this thread for the analysis.

And to complete this thread, we don’t expect the concept of base plugin to be used anymore. We have plans to deprecate/remote it:
https://jira.sonarsource.com/browse/SONAR-10286

1 Like

Hi Julien,
I can confirm that also in my case I’m using AEM rules plugin…can be useful to open an issue on their GitHub repo?

Hi All,

thanks for raising the issue. As I recall, we did take advantage of shared class loader functionality in some way.

We’re currently investing a bit in development of the plugin. Support for new language (HTL) requires us to upgrade API dependencies anyway, so that may help. It’s worth to add that we’re always aiming to be compatible with each LTS version.

Please bare with us as we investigate & fix the issue along with testing of compatibility in coming days. It would be also great, if you could help testing v0.11 Release Candidate version when it comes out. It will include couple of new features along with this fix.

For now, I’d recommend to stick with Java 5.7.

Feel free to subscribe to releases:
https://github.com/Cognifide/AEM-Rules-for-SonarQube/releases.atom

Here’s an update!

We’ve removed dependency to Java plugin and as we were using some helpers which were not exposed in API, we had to provide our implementation to fill this gap. So now we only depend on API, which is cool.

We’ve just released version v0.11-RC1, which should be compatible with Java 5.8 and you’ll also get some additional rules with it.

It would be great if you could test it in your project and report any false positive’s for 2 new rules. We’ll be testing it against our current projects and as long as it will behave stable, we’ll release v0.11 to Marketplace this week.

2 Likes

To wrap up this topic, version 0.11 has been released and is awaiting to be added to the Marketplace. Thanks everyone for your contribution.

1 Like