StackOverflowError when analyzing Kotlin code

  • Source control: GitHub
  • CI: GitHub Actions
  • Scanner command used: mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=xyz
  • Error:
[INFO] Sensor Kotlin Sensor [kotlin]
[INFO] 991 source files to be analyzed
[redacted]
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:26 min
[INFO] Finished at: 2023-04-24T07:00:29Z
[INFO] ------------------------------------------------------------------------
---------------------------------------------------
constituent[0]: file:/usr/share/apache-maven-3.8.8/conf/logging/
constituent[1]: file:/usr/share/apache-maven-3.8.8/lib/javax.annotation-api-1.2.jar
constituent[2]: file:/usr/share/apache-maven-3.8.8/lib/maven-artifact-3.8.8.jar
constituent[3]: file:/usr/share/apache-maven-3.8.8/lib/plexus-utils-3.3.1.jar
constituent[4]: file:/usr/share/apache-maven-3.8.8/lib/org.eclipse.sisu.inject-0.3.5.jar
constituent[5]: file:/usr/share/apache-maven-3.8.8/lib/org.eclipse.sisu.plexus-0.3.5.jar
constituent[6]: file:/usr/share/apache-maven-3.8.8/lib/maven-resolver-impl-1.6.3.jar
Exception in thread "main" java.lang.StackOverflowError
constituent[7]: file:/usr/share/apache-maven-3.8.8/lib/slf4j-api-1.7.36.jar
	at java.base/java.util.ArrayList.indexOfRange(ArrayList.java:299)
constituent[8]: file:/usr/share/apache-maven-3.8.8/lib/plexus-component-annotations-2.1.0.jar
	at java.base/java.util.ArrayList.indexOf(ArrayList.java:286)
constituent[9]: file:/usr/share/apache-maven-3.8.8/lib/maven-resolver-transport-wagon-1.6.3.jar
	at java.base/java.util.ArrayList.contains(ArrayList.java:275)
constituent[10]: file:/usr/share/apache-maven-3.8.8/lib/maven-settings-3.8.8.jar
	at org.jetbrains.kotlin.types.StarProjectionImplKt$buildStarProjectionTypeByTypeParameters$1.get(StarProjectionImpl.kt:55)
constituent[11]: file:/usr/share/apache-maven-3.8.8/lib/jcl-over-slf4j-1.7.36.jar
	at org.jetbrains.kotlin.types.TypeConstructorSubstitution.get(TypeSubstitution.kt:60)
constituent[12]: file:/usr/share/apache-maven-3.8.8/lib/wagon-http-3.5.3-shaded.jar
	at org.jetbrains.kotlin.types.TypeSubstitutor.unsafeSubstitute(TypeSubstitutor.java:206)
constituent[13]: file:/usr/share/apache-maven-3.8.8/lib/maven-builder-support-3.8.8.jar
	at org.jetbrains.kotlin.types.TypeSubstitutor.substituteTypeArguments(TypeSubstitutor.java:373)
constituent[14]: file:/usr/share/apache-maven-3.8.8/lib/maven-shared-utils-3.3.4.jar
	at org.jetbrains.kotlin.types.TypeSubstitutor.substituteCompoundType(TypeSubstitutor.java:352)
constituent[15]: file:/usr/share/apache-maven-3.8.8/lib/maven-repository-metadata-3.8.8.jar
	at org.jetbrains.kotlin.types.TypeSubstitutor.unsafeSubstitute(TypeSubstitutor.java:287)
constituent[16]: file:/usr/share/apache-maven-3.8.8/lib/maven-embedder-3.8.8.jar
	at org.jetbrains.kotlin.types.TypeSubstitutor.substituteWithoutApproximation(TypeSubstitutor.java:164)
constituent[17]: file:/usr/share/apache-maven-3.8.8/lib/plexus-interpolation-1.26.jar
	at org.jetbrains.kotlin.types.TypeSubstitutor.substitute(TypeSubstitutor.java:149)
constituent[18]: file:/usr/share/apache-maven-3.8.8/lib/maven-model-builder-3.8.8.jar
	at org.jetbrains.kotlin.types.TypeSubstitutor.substitute(TypeSubstitutor.java:143)
constituent[19]: file:/usr/share/apache-maven-3.8.8/lib/maven-settings-builder-3.8.8.jar
	at org.jetbrains.kotlin.types.StarProjectionImplKt.buildStarProjectionTypeByTypeParameters(StarProjectionImpl.kt:60)
constituent[20]: file:/usr/share/apache-maven-3.8.8/lib/maven-model-3.8.8.jar
	at org.jetbrains.kotlin.types.StarProjectionImplKt.starProjectionType(StarProjectionImpl.kt:65)
constituent[21]: file:/usr/share/apache-maven-3.8.8/lib/maven-slf4j-provider-3.8.8.jar
	at org.jetbrains.kotlin.types.StarProjectionImpl$_type$2.invoke(StarProjectionImpl.kt:35)
constituent[22]: file:/usr/share/apache-maven-3.8.8/lib/maven-resolver-provider-3.8.8.jar
	at org.jetbrains.kotlin.types.StarProjectionImpl$_type$2.invoke(StarProjectionImpl.kt:34)
constituent[23]: file:/usr/share/apache-maven-3.8.8/lib/plexus-cipher-2.0.jar
	at kotlin.SafePublicationLazyImpl.getValue(LazyJVM.kt:107)
	at org.jetbrains.kotlin.types.StarProjectionImpl.get_type(StarProjectionImpl.kt:34)
	at org.jetbrains.kotlin.types.StarProjectionImpl.getType(StarProjectionImpl.kt:38)
	at org.sonarsource.kotlin.checks.VoidShouldBeUnitCheckKt$flattenTypeArguments$1.invoke(VoidShouldBeUnitCheck.kt:79)
	at org.sonarsource.kotlin.checks.VoidShouldBeUnitCheckKt$flattenTypeArguments$1.invoke(VoidShouldBeUnitCheck.kt:79)
	at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:315)
	at kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:303)
	at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:316)
	at kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:303)
	at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:316)
	etc.

Hi, we suddenly started getting StackOverflowError when analyzing Kotlin maven project. Please see the stack trace above. Any ideas what might cause it? Thank you in advance!

Kotlin version: 1.6.21
JDK 17

I would suggest appending -X to your command to get DEBUG level logs, and see if a specific file is referenced before the failure. If so, we’ll need that file in order to further debug.

I did that, thanks, but it didn’t provide any useful information. Last debug log before the crash is about CPD:

[DEBUG] 08:39:59.686 Not enough content in ‘[redacted]’ to have CPD blocks, it will not be part of the duplication detection

Hello @bartkuzio,

Thanks for the message.

I think I found the potential issue in the code. To test it better, could you, please, provide the content of the file TypeSubstitutor.java? I think this is the one producing the Exception.

Regards,
Margarita

Hi, thank you for looking into it. This is a class from kotlin-reflect library

Link to the class from Kotlin github repo:

Sorry,

I think I was looking in the wrong place :slight_smile: It couldn’t happen because of a Java file, as it’s a Kotlin check, of course.

I found the issue in the code, however, would be nice to see the complete log, so I can understand which file is triggering it. Could, you please share the complete log?

And here is the ticket to fix it: [SONARKT-313] - Jira

Regards,
Margarita

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.