Incompatible versions of SonarLint plugin, SonarQube, SonarJava and JDK?

All my source code is designed and compiled against the most recent version of Java 1.8 and builds just fine in IntelliJ IDEA Community 2019.2 (when set to a project JDK of 1.8, obviously).

I have access to a SonarQube server instance and want to run code analysis on a new project, but the SonarQube version is about 18 months old, i.e. SonarQube 7.0.36138, with a SonarJava plugin of 5.3.13828. My management team are currently ‘unwilling’ to change that for fear of breaking the analysis of other Java projects.

As an alternative, I can use SonarScanner to do our analysis: this works and will update the SQ dashboard, but I’d much prefer to use the IntelliJ SonarLint plugin to get code analysis directly inside IntelliJ (and send results to the SQ binding).

So I tried installing the latest version of SonarLint (4.2.0.3434) from the IntelliJ marketplace. It is all configured and connects OK to the SQ binding but, when I run a code analysis, all I’m getting is:

File won’t be refreshed because there were errors during analysis

against every file. The log provides other output, such as the plugins that were loaded, e.g.:

Found plugin: sonar-java-plugin-5.14.0.18788.jar

but no other reason as to why the scan is failing.

My assumption is that there is some JDK version incompatibility going on somewhere - but that’s a guess and I’m stuck as regards a way to proceed; in a way, I would have thought that an older version of SQ would have been OK for analysing 1.8 Java…

Can anyone explain why I’m getting these blanket error messages and what my options are here for providing myself with SonarLint capability ? Any way of analysing my 1.8 code with the versions of everything that I’ve got ?

Thanks

Hi @gazroo

Please enable verbose logs to see more details about the error (look at the FAQ). It will help us to guide you with the best option.

++

Hi again, thanks for the initial response. Sorry I didn’t do this logging straight away!

Here’s the stack trace you requested for one of our typical class sources. Does this help ?

Unable to create symbol table for : C:\Users\username\Documents\proc\proc_rt\proc-rt\src\com\companyname\proc\messages\GetGroupsResponse.java
java.lang.IllegalArgumentException: Unsupported class file major version 55
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:166)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:148)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:136)
	at org.sonar.java.resolve.BytecodeCompleter.loadClass(BytecodeCompleter.java:204)
	at org.sonar.java.resolve.Symbols.<init>(Symbols.java:176)
	at org.sonar.java.resolve.SemanticModel.createFor(SemanticModel.java:59)
	at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:110)
	at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:96)
	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.sonarsource.sonarlint.core.analyzer.sensor.SensorsExecutor.executeSensor(SensorsExecutor.java:81)
	at org.sonarsource.sonarlint.core.analyzer.sensor.SensorsExecutor.execute(SensorsExecutor.java:72)
	at org.sonarsource.sonarlint.core.container.analysis.AnalysisContainer.doAfterStart(AnalysisContainer.java:134)
	at org.sonarsource.sonarlint.core.container.ComponentContainer.startComponents(ComponentContainer.java:125)
	at org.sonarsource.sonarlint.core.container.ComponentContainer.execute(ComponentContainer.java:110)
	at org.sonarsource.sonarlint.core.container.storage.StorageAnalyzer.analyze(StorageAnalyzer.java:75)
	at org.sonarsource.sonarlint.core.container.storage.StorageContainerHandler.analyze(StorageContainerHandler.java:81)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.lambda$analyze$0(ConnectedSonarLintEngineImpl.java:152)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.withReadLock(ConnectedSonarLintEngineImpl.java:344)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.withReadLock(ConnectedSonarLintEngineImpl.java:334)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.analyze(ConnectedSonarLintEngineImpl.java:149)
	at org.sonarlint.intellij.core.ConnectedSonarLintFacade.analyze(ConnectedSonarLintFacade.java:74)
	at org.sonarlint.intellij.core.SonarLintFacade.startAnalysis(SonarLintFacade.java:63)
	at org.sonarlint.intellij.analysis.SonarLintAnalyzer.analyzeModule(SonarLintAnalyzer.java:97)
	at org.sonarlint.intellij.analysis.SonarLintTask.analyze(SonarLintTask.java:181)
	at org.sonarlint.intellij.analysis.SonarLintTask.run(SonarLintTask.java:105)
	at org.sonarlint.intellij.analysis.SonarLintJobManager.lambda$runTask$1(SonarLintJobManager.java:120)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:169)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:591)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:537)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:59)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:156)
	at org.sonarlint.intellij.analysis.SonarLintJobManager.lambda$runTask$2(SonarLintJobManager.java:120)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

Unsupported class file major version 55

means that the bytecode was generated with a target for Java 11. Can you check your project settings to ensure language level is set to 8:

@Julien_HENRY
Hi - I had a feeling you would ask me this, which is why I’m mystified that SonarLint isn’t working for this project. Just to confirm, the following has ALWAYS been the setting for this project:

image

I’m confused…

UPDATE

If I unbind the project from SonarQube, I successfully get analysis of my classes (which I know for definite are built against Java minor version 52 (J8) because I’ve run javap against the class files).

If I then rebind the project to the SQ server again, the original problem comes back.

Does that help ?

When you unbind the project, you are using the SonarJava analyzer bundled with SonarLint, which is very recent and supports Java 11, so that explains why you don’t have the issue.

To me you are probably bitten by: https://jira.sonarsource.com/browse/SONARJAVA-3056
Even if the message says that the error occurs when reading bytecode of GetGroupsResponse.java, it might be in fact coming from a dependency from the JDK (if the class extends or import a JDK class).
In this case SonarJava will try to load the bytecode of the runtime JDK (= the JDK used to run the IDE).

We haven’t found a solution to this issue yet, so you have few other options:

  • update SonarJava on your SonarQube server
  • don’t use connected mode
  • run your IDE with JDK 8 (this one might not be easy/supported with latest IntelliJ releases)
1 Like