Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar - OutOfMemoryError: Java heap space

Tags:

I am deploying a large Java project on Sonar using "Findbugs" as profile and getting the error below:

Caused by: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space 

What i have tried to resolve this:

  1. Replaced %SONAR_RUNNER_OPTS% with -Xms256m -Xmx1024m to increase the heap size in sonar-runner bat file.
  2. Put "sonar.findbugs.effort" parameter as "Min" in Sonar global parameters.

But both of above methods didn't work for me.

like image 629
shekhar verma Avatar asked Oct 19 '12 04:10

shekhar verma


People also ask

How do I fix Java heap space error?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

How do I increase Sonarqube memory?

You can increase the maximum memory allocated to the appropriate process by increasing the -Xmx memory setting for the corresponding Java process in your sonar. properties file: For Web: sonar. web.

What is OutOfMemoryError Java heap space?

OutOfMemoryError is a runtime error in Java which occurs when the Java Virtual Machine (JVM) is unable to allocate an object due to insufficient space in the Java heap. The Java Garbage Collector (GC) cannot free up the space required for a new object, which causes a java. lang.

What is Exception in thread main Java Lang OutOfMemoryError Java heap space?

The OutOfMemoryError Exception in Java looks like this: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space. Usually, this error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory. No more memory could be made available by the garbage collector.


1 Answers

I had the same problem and found a very different solution, perhaps because I'm having a hard time swallowing the previous answers / comments. With 10 million lines of code (that's more code than is in an F16 fighter jet), if you have a 100 characters per line (a crazy size), you could load the whole code base into 1GB of memory. I set it 8GB of memory and it still failed. Why?

Answer: Because the community Sonar C++ scanner seems to have a bug where it picks up ANY file with the letter 'c' in its extension. That includes .doc, .docx, .ipch, etc. Hence, the reason it's running out of memory is because it's trying to read some file that it thinks is 300mb of pure code but really it should be ignored.

Solution: Find the extensions used by all of the files in your project (see more here):

dir /s /b | perl -ne 'print $1 if m/\.([^^.\\\\]+)$/' | sort -u | grep c 

Then add these other extensions as exclusions in your sonar.properties file:

sonar.exclusions=**/*.doc,**/*.docx,**/*.ipch 

Then set your memory limits back to regular amounts.

%JAVA_EXEC% -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m %SONAR_RUNNER_OPTS% ... 
like image 121
Ryan Shillington Avatar answered Sep 29 '22 22:09

Ryan Shillington