ClassCastException on

  • ALM used GitHub
  • CI system used Circle CI
  • Scanner command used ./gradlew app:sonar
  • Language Kotlin
  • Error observed
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Collection (java.lang.String and java.util.Collection are in module java.base of loader 'bootstrap')
        at org.sonarqube.gradle.SonarUtils.appendProps(
        at org.sonarqube.gradle.SonarUtils.appendSourcesProp(
  • Steps to reproduce
  1. We use Gradle Convention plugins(if relevant) and our sources property is like this:
    property(“sonar.sources”, “${project.projectDir}/src/main/kotlin”)

Can confirm that is working fine.


Hello @Laurynas, welcome to the Sonar Community.

Usually, the Sonar Scanner Gradle plugin is able to detect sources automatically, so there should be no need for property(“sonar.sources”, “${project.projectDir}/src/main/kotlin”) . Could you please run the scan without setting the property? Does the issue still happen?

A second option is to replace property(“sonar.sources”, “${project.projectDir}/src/main/kotlin”) with property("sonar.sources", listOf("${ project.projectDir }/src/main/kotlin")).

In case the problem is not solved, can you provide us with a small reproducer? A small project that we can easily run on our side to reproduce this issue.



Hello @angelo.buono,

I’m not the OP, but I’m experiencing the same issue. Regarding your suggestions:

  • Without setting the property, the issue doesn’t appear. In general, it would still be good to be able to set it, though.
  • Using listOf produces an UnsupportedOperationException.

My suspicion after a quick look into the code is that it’s caused by this change: SONARGRADL-128 Put all Gradle Build scripts in root sonar.sources onl… · SonarSource/sonar-scanner-gradle@c935bcd · GitHub
rawProperties seems to contain String-valued properties and appendProps expects a Collection.



Thank you @ms-tng for helping speed up the investigation.

I have opened an issue to fix the bug, you can track the progress at [SONARGRADL-133] - Jira.



1 Like

Any update? I have disabled Sonar in CI since this bug is happening.

Hello @JavierSC, there is no plan to do any work on the Gradle Scanner for this year due to the proximity to Christmas and New Year. The issue will be addressed within the first quarter of 2024.


It’s been open since October, I don’t think it will be fixed by anyone, does anyone have any suggestions for other tools besides Sonar (like Embold, etc.) and that the team is working on compatibility for Java 17?

Hey @Lucas_Campos, I’m sorry you’re facing this issue. We’ve only faced relatively few reports of this issue.

Like @angelo.buono said:

The issue will be addressed within the first quarter of 2024.

So it’s a real stretch to say:

It works with property(“sonar.sources”, mutableListOf(“src/main, src/main2”)) for me.