Sonarqube has java.lang.NoClassDefFoundError: kotlin/jvm/internal/Ref$IntRef

Hi,

Versions:

  • JDK: OpenJDK Runtime Environment Corretto-11.0.20.9.1 (build 11.0.20.1+9-LTS)
  • Gradle Wrapper: 8.0
  • Sonar: org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:5.1.0.4882
  • Repository language: Java

Issue happens running both locally (Macbook) and on GitLab CI.

I have tried a multitude of various versions of the sonar plugin and also gradle, but still see this error.

I also tried including kotlin on various gradle classpaths (org.jetbrains.kotlin:kotlin-stdlib:2.0.20), and the error still appears, then I realised the stack trace includes ā€œIsolatedClassloaderā€, which tells me that was never going to work anyway.

Despite the error, I still see all the subprojects being reported in the Sonarqube UI for our organisation, so I donā€™t know how this error impacts sonar reporting.

Error observed:

Exception in thread "OkHttp TaskRunner" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Ref$IntRef
        at okhttp3.internal.http2.Http2Connection.shutdown(Http2Connection.kt:419)
        at okhttp3.internal.http2.Http2Connection.close$okhttp(Http2Connection.kt:449)
        at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:627)
        at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:609)
        at okhttp3.internal.concurrent.TaskQueue$execute$1.runOnce(TaskQueue.kt:98)
        at okhttp3.internal.concurrent.TaskRunner.runTask(TaskRunner.kt:116)
        at okhttp3.internal.concurrent.TaskRunner.access$runTask(TaskRunner.kt:42)
        at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:65)
        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:829)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Ref$IntRef
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
        at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527)
        ... 11 more

Hey there.

What version of SonarQube are you using? You can find this info in the footer of your SonarQube instance.

Hi Colin

Community Edition v9.9.5 (build 90363)

Is that the version youā€™re looking forā€¦?

It is!

This problem was most likely fixed by SONARKT-372, which removed our use of the Gradle Tooling API to detect build scripts. This was introduced in SonarQube v10.4.

With this exception present, the worst-case scenario is that these rules are not applied to your Gradle files.

I donā€™t have a workaround in mind to prevent this error if you canā€™t move SonarQube versions, but (likely?) adding an exclusion like sonar.exclusions=**/*.gradle.kts should get rid of the error. If you werenā€™t previously aware, your Gradle files were being analyzed (most users arenā€™t)ā€¦ this might be a good option.

Thanks for your reply Colin.

We will follow up on our end with upgrade options, and ignore the exception in the meantime.

Cheers

Hi Colin,

I tried adding the following to the gradle sonar properties, but still see the exception

property 'sonar.exclusions', "**/*.gradle.kts"

Thanks for the update @tony.ap.2024. Unfortunately I donā€™t have a project/environment where I reproduce the issue, so thereā€™s not much I can suggest other than ignore the error for now.

1 Like

Hello Colin, just ran into the same issue: s. GitHub action run.
Tried already to exclude build files with: property("sonar.exclusions", "**/gradle.build.kts,**/buildSrc/**").
Iā€™ve create a new branch ā€˜sonarscannerā€™ which I can leave there for a whileā€¦
best regards

Hi Peter,

Welcome to the community!

The problem seems to happen during the taint analysis execution. If you donā€™t care about the taint analysis, you can disable the following rules: S2076, S2078, S2083, S2091, S2631, S3649, S5131, S5135, S5144, S5145, S5146, S5147, S5334, S5496, S5883, S6096, S6173, S6287, S6350, S6384, S6390, S6398, S6399, S6547, S6549, S7044. It should solve your problem.

Otherwise, I will forward it to the team responsible for the taint analysis so they can investigate further. Let them know if you need more help.

@p3t ,

unfortunately, I was not able to reproduce this problem yet.

Likely unrelated to the error but worth a try: seeing your linked branch, the Sonar task does not seem to be correctly configured for a multi-project Gradle project. See SonarScanner for Gradle . You need to apply the sonarqube plugin in your main build.gradle.kts and move the settings there too.