java.lang.OutOfMemoryError: Java heap space in jenkins sonar scan stage

I am using jenkins plugin i.e SonarQube Scanner Version: 2.15

I have 3 projects to scan e.g xyz_server, xyz_client and xyz_plugins.

I have 3 stages in my jenkins pipeline for sonar scan of above projects.
out of 3 projects for xyz_server and xyz_plugins, every time when I run scan analysis it gets completed without any issue. but for xyz_client project I’m getting java.lang.OutOfMemoryError: Java heap space issue every time.

I’m using jenkins slave node to run pipeline.
console output shows Analysis successful for xyz_client but throws above error.
analysis gets updated on sonar server UI correctly for xyz_client but only issue is pipeline fails with java.lang.OutOfMemoryError issue.

when I compared xyz_client vs xyz_server heap memory usage while running sonar scan stage,
it is 4.5gb for xyz_client and 0.5gb for xyz_server.

below is the console output :

java.lang.OutOfMemoryError: Java heap space
	at java.base/java.lang.StringLatin1.toChars(Unknown Source)
	at java.base/java.lang.String.toCharArray(Unknown Source)
	at java.base/sun.nio.fs.UnixPath.encode(Unknown Source)
	at java.base/sun.nio.fs.UnixPath.<init>(Unknown Source)
	at java.base/sun.nio.fs.UnixFileSystem.getPath(Unknown Source)
	at java.base/java.nio.file.Path.of(Unknown Source)
	at java.base/java.nio.file.Paths.get(Unknown Source)
	at hudson.FilePath.glob(
	at hudson.FilePath$ListGlob.invoke(
	at hudson.FilePath$ListGlob.invoke(


org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 71601352-1b84-40fb-8045-12e9f5ff12ca
Caused: Remote call on JNLP4-connect connection from failed
	at hudson.FilePath.act(
	at hudson.FilePath.act(
	at hudson.FilePath.list(
	at hudson.FilePath.list(
	at hudson.FilePath.list(
	at hudson.plugins.sonar.utils.SonarUtils.extractReportTask(
	at hudson.plugins.sonar.utils.SonarUtils.addBuildInfoTo(
	at hudson.plugins.sonar.SonarBuildWrapper$AddBuildInfo.tearDown(
	at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Callback.finished(
	at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Execution2$Callback2.finished(
	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution$TailCall.lambda$onSuccess$0(
	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(
	at java.base/java.util.concurrent.Executors$
	at java.base/
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.base/java.util.concurrent.ThreadPoolExecutor$
	at java.base/

following ss shows the original heap size of slave node:

following ss shows memory usage of xyz_client sonar scan process

please help me to resolve this issue

Welcome :slight_smile:

you need to configure SONAR_SCANNER_OPTS via https://yourjenkins/manage/configure
For us -Xmx4G works fine.


1 Like

thank you for quick suggestion,
I’ll try and update here

even after setting SONAR_SCANNER_OPTS to around 8gb it is still giving me same error

At a second glance i see you’re using Ant.
What is your ANT_OPTS setting in Jenkins ?

actually I’m not using Ant and do not have ANT_OPTS setting as well in jenkins.

Somehow the Ant api seems to be involved, maybe via Gradle (using parts of Ant under the hood) or
Groovy antbuilder !?
From the stacktrace i assume that the Ant directory scanner is responsible for the OOM.

We need some more details about your pipeline.
Your screenshot has openjdk 1.8.0_372, but the Sonar analysis needs to run with Java 11 or 17
for the latest Sonarqube versions. What’s your Sonarqube version ?
Would it be possible to post your Jenkinsfile to get more insight with sensitive parts redacted ?

could you please provide me with your email address. I’ll send you the jenkins file.

I have sent you a PM in this forum, just reply and attach the Jenkinsfile.

Jenkinsfile.txt (31.8 KB)

@Rebse I have attached jenkins file in text format.

I’m using SonarQube Community Edition - Version 10.0

@Rebse have you got chance to go through jenkins file?
have you identified the cause of the “out of memory” issue?


still wondering about the entries in the stacktrace.
ok, you’re using sonar-scanner - npm which is not provided by Sonarsource
GitHub - bcaudan/node-sonar-scanner: Sonar scanner for node

Our npm builds all use the Sonar CLI scanner instead, the Sonar CLI scanner will respect the

If using npm sonar-scanner you may try to increase the heap via
export NODE_OPTIONS="--max-old-space-size=8192" in your pipeline.

But i recommend using the Sonar CLI scanner for npm builds, means
Jenkins extension for Sonarqube 2.15


Sonar CLI scanner 4.8


1 Like

Hi @Rebse , I’m using sonarqube-scanner - npm (

GitHub - SonarSource/sonar-scanner-npm: SonarQube Scanner for the JavaScript world

I tried NODE_OPTIONS as well but no luck. I’m getting same error.

My doubt is heap memory requirement is more than 4.5gb and if configured MaxHeapMemory = 4.2gb,
then is it possible to increase heap memory using NODE_OPTIONS or SONAR_SCANNER_OPTS?
will it limit the memory to 4.2gb because of configured MaxHeapMemory, even though we tried increasing it to 6gb or 8gb.

What’s the output of free -th ?

@Rebse this is jenkins slave node memory when no jenkins job running

What are your Jenkins Java VM settings (Xmx …) ?, see jenkins.xml

@Rebse we do not have jenkins.xml also there is no configuration related to jvm or java

maybe we can use Additional arguments as shown in above ss to set any additional argument.

However I tried setting SONAR_SCANNER_OPTS here as well and it did’t resolved that issue.

The jenkins.xml is located on the Jenkins controller (FKA Jenkins master), it contains the Java VM settings.
Our controller has - see https://yourjenkins/manage/configure


You may try this, but i recommend to switch to Sonar scanner CLI for npm.

I tried sonar scanner cli on my local system( windows OS) and by setting

but it continuously scans the project and scan not completed even though waited for 4-5 hours.

I’m using docker image of sonarqube to launch sonar server

that’s why I’m not trying it on jenkins.