Error in SonarLint for IntelliJ - NoClassDefFoundError

Environment:

  • Java: JetBrains s.r.o. 11.0.12
  • OS: Mac OS X x86_64
  • IDE: IntelliJ IDEA 2021.2.3
  • SonarLint: 6.0.0.37696
java.lang.NoClassDefFoundError: org/sonar/plugins/java/api/CheckRegistrar
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
	at org.sonar.classloader.ClassRealm.loadClassFromSelf(ClassRealm.java:125)
	at org.sonar.classloader.ParentFirstStrategy.loadClass(ParentFirstStrategy.java:37)
	at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:87)
	at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:76)
	at com.fidelity.fpcms.sonar.MyJavaRulesPlugin.define(MyJavaRulesPlugin.java:36)
	at o.ss.sl.core.container.global.ExtensionInstaller.install(ExtensionInstaller.java:72)
	at o.ss.sl.core.container.global.ExtensionInstaller.install(ExtensionInstaller.java:62)
	at o.ss.sl.core.container.global.GlobalExtensionContainer.doBeforeStart(GlobalExtensionContainer.java:36)
	at o.ss.sl.core.container.ComponentContainer.startComponents(ComponentContainer.java:124)
	at o.ss.sl.core.container.storage.StorageContainer.doAfterStart(StorageContainer.java:161)

Hi,

It seems you have a custom plugin implementing some Java rules on your SonarQube server. This is normally supported, but here I guess you might have an outdated version of the Java analyzer, no more supported by SonarLint.
To verify that, could you please open in a web browser the page: https://<your sonarqube server>/api/plugins/installed and post the result here.

Thanks

I have no server setup in SonarQube, and am unable to load the SonarLint settings in order to figure out where to look (above error)…

The stacktrace indicates the use of connected mode. Maybe you did try to setup connection to a SonarQube at some point?

Aren’t you able to open the SonarLint binding dialog to unbind your project?

If not, you can try to manually edit the project configuration:

  • close your project
  • edit the file .idea/sonarlint.xml
  • set bindingEnabled attribute to false
  • restart the project

I was able to disable bindings via editing sonarSettings.xml. That allowed me to bring up the SonarLint binding dialog when I started IntelliJ (toggling on/off updated that setting). The same exception occurs with bindings disabled. For reference, current sonarSettings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="projectSettings">
    <option name="alternativeWorkingDirPath" value="" />
    <option name="localAnalysisScripName" value="&lt;NO LOCAL ANALYSIS&gt;" />
    <option name="serverName" value="&lt;NO SONAR&gt;" />
    <option name="useAlternativeWorkingDir" value="false" />
    <option name="workingDirSelection" value="&lt;PROJECT&gt;" />
    <option name="bindingEnabled" value="false" /> <!-- added 10/28/21 -->
  </component>
</project>

(comment disappeared when I toggled on/off in the dialog)

Hi,

This file (sonarSettings.xml) and those settings (localAnalysisScripName, useAlternativeWorkingDir, …) are not part of the official SonarLint plugin. It seems they come from a plugin named “SonarQube Analyzer” that is not supported by SonarSource.
I suggest you remove this plugin, and ensure you are using an official SonarLint build.

The SonarLint settings file where the binding configuration is stored is named sonarlint.xml.

I removed both the SonarLint and SonarQube plugins, restarted IntelliJ, rm -rf .idea/sonar* (in my project), installed the SonarLint plugin, restarted IntelliJ…

Same NoClassDefFoundError for CheckRegistrar

As a followup, could this be the root cause? Before clicking on “Open SonarLint Settings” link, it has the following in the popup:

SonarLint failed to analyze TypeScript code
					SonarLint requires Node.js runtime version 10.12.0 or later to analyze TypeScript code.
					Please configure the Node.js path in the SonarLint settings.
					Open SonarLint Settings

If so, is there a way to add that in an xml? FWIW, no sonarlint.xml nor sonarSettings.xml since I did the clean install this morning…

When you have removed SonarLint and restarted your IDE, you don’t have the error anymore?

Correct - SonarLint is no longer there to give the error.

Then if you still see the exact same stacktrace as you reported in the first post, it means SonarLint is still in connected mode (using the cached data from a SonarQube server).
Try to open a brand new project since the binding settings are stored in project settings.