Sonar Analysis gets failed with OutOfMemoryError when using FindBugs

  • Enterprise Edition Version 9.5 (build 56709)
  • Findbugs 4.2.0 (Analyze Java, Scala, Closure and JSP code with SpotBugs. 4.7.1)

My Sonar build is getting failed with below error, I have already tried increasing the below config nut no luck.

sonar.ce.javaOpts=-Xmx4096m -Xms2048m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true

As per few KB articles I have also added below parameter to my pipeline but still see same issue.

export SONAR_SCANNER_OPTS=-4096m

Note: We use MAVEN to scan sonar and not sure if above parameter works with Maven.

06-Jul-2022 17:54:23	[INFO] BUILD FAILURE
06-Jul-2022 17:54:23	[INFO] ------------------------------------------------------------------------
06-Jul-2022 17:54:23	[INFO] Total time: 01:42 h
06-Jul-2022 17:54:23	[INFO] Finished at: 2022-07-06T17:54:23-04:00
06-Jul-2022 17:54:23	[INFO] Final Memory: 259M/920M
06-Jul-2022 17:54:23	[INFO] ------------------------------------------------------------------------
06-Jul-2022 17:54:23	[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project v3-product: Can not execute Findbugs: java.lang.OutOfMemoryError: Java heap space: failed reallocation of scalar replaced objects -> [Help 1]
06-Jul-2022 17:54:23	[ERROR] 
06-Jul-2022 17:54:23	[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
06-Jul-2022 17:54:23	[ERROR] Re-run Maven using the -X switch to enable full debug logging.
06-Jul-2022 17:54:23	[ERROR] 
06-Jul-2022 17:54:23	[ERROR] For more information about the errors and possible solutions, please read the following articles:

Thanks,
Sunil Palugula

Hi Sunil,

The sonar.ce.javaOpts setting won’t affect your analysis. The SONAR_SCANNER_OPTS value would affect analysis if you weren’t analyzing with Maven. Since you are, you should export MAVEN_OPTS instead. The docs should help.

And you may need to go higher than 4096m. Keep increasing until it works (or your machine runs out of memory).

That said, if the problem happens with FindBugs, the simple solution is to not run FindBugs and/or to report the problem to the FindBugs maintainers.

 
HTH,
Ann

We have below maven option already set on our pipeline.

MAVEN_OPTS=“-Xmx20480m -XX:MaxPermSize=4096m -XX:+UseSerialGC” JAVA_OPTS=“-Xmx20480m -Xms4096m”