When I run the sonarqube analysis and I use the sonar-java plugin, the analysis does not complete and gets stuck in a loop. The analysis then crash on a StackOverflowError:
Caused by: java.lang.StackOverflowError
at org.sonar.java.checks.NoTestInTestClassCheck.getAllMembers(NoTestInTestClassCheck.java:181)
at org.sonar.java.checks.NoTestInTestClassCheck.getAllMembers(NoTestInTestClassCheck.java:163)
at org.sonar.java.checks.NoTestInTestClassCheck.lambda$getAllMembers$5(NoTestInTestClassCheck.java:179)
The analysed project has 5.2 million lines of source code, uses 9 programing languages and uses build system in gradle.
These lines are permanently repeating in stacktrace:
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743)
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
Thanks for the feedback. The stackoverflow is caused by rule squid:S2187, which have indeed been updated with release 5.9 of SonarJava (SONARJAVA-2924).
I know you obviously have a huge code base, but could you check if you have Java test classes using the Enclosed JUnit runner?
It would also hugely help if you could identify the file(s) which is causing the analysis to fail. I’m however certain it’s a test class. Without reproducer, I won’t be able to identify what patterns cause the engine to loop.
Now, if you just need to pass the analysis, as a temporary workaround, you could remove rule S2187 from your Quality Profile while we are working on a fix.
I will temporarily ban the rule squid:S2187 . Thanks for the suggestion.
Yes, our code contains some Java test classes that use the Enclosed JUnit runner.
That specific test class that causes the failure does not use this runner. Unfortunately I cannot send you its implementation but from my observations it could be caused by the inner classes that has “test” sub-string in its name but is not intended to be a test, basically its just some kind of helper:
public class VeryBadTest extends BaseTest
{
...
public static class helperclasstest extends handler
{
.....
// no test here
}
}
Thanks for your answer. Even if not causing directly the issue, the code snippet you added helped in my investigation to identify the problem, which comes from cycle in symbol type hierarchy. I created the following JIRA ticket to handle it: SONARJAVA-2974
FYI: I managed to reproduce the StackOverflowError you are getting with the following test class:
class ATest implements I1 {}
interface I1 {
class Handler implements I1 {}
}