Sonar - OutOfMemoryError: Java heap space

2019-04-03 10:09发布

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.

6条回答
贼婆χ
2楼-- · 2019-04-03 10:26

I know this thread is a bit old but this info might help someone.

For me the problem was not like suggested by the top-answer with the C++ plugin. Instead my problem was the Xml-Plugin (https://docs.sonarqube.org/display/PLUG/SonarXML) after I deactivated it the analysis worked again.

查看更多
闹够了就滚
3楼-- · 2019-04-03 10:27

The problem is on FindBugs side. I suppose you're analyzing a large project that probably has many violations. Take a look at two threads in Sonar's mailing list having the same issue. There are some ideas you can try for yourself.

http://sonar.15.n6.nabble.com/java-lang-OutOfMemoryError-Java-heap-space-td4898141.html

http://sonar.15.n6.nabble.com/java-lang-OutOfMemoryError-Java-heap-space-td5001587.html

查看更多
ゆ 、 Hurt°
4楼-- · 2019-04-03 10:31

I had the same problem when running sonar with maven. In my case it helped to call sonar separately:

mvn clean install && mvn sonar:sonar

instead of

mvn clean install sonar:sonar

http://docs.sonarqube.org/display/SONAR/Analyzing+with+Maven

Remark: Because my solution is connected to maven, this is not the direct answer for the question. But it might help other users who stumple upon it.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-04-03 10:32

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% ...
查看更多
我命由我不由天
6楼-- · 2019-04-03 10:40

What you can do it to create your own quality profile with just some Findbugs rules at first, and then progressively add more and more until you reach his OutOfMemoryError. There's probably only a single rule that makes all this fail because your code violates it - and if you deactivate this rule, it will certainly work.

查看更多
霸刀☆藐视天下
7楼-- · 2019-04-03 10:41

this has worked for me:

SONAR_RUNNER_OPTS="-Xmx3062m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m"

I set it direct in the sonar-runner(.bat) file

查看更多
登录 后发表回答