Random failure of SonarQube throwing "java.lang.NullPointerException" exception

Hello,

I got random failure (unclear to me what is the trigger) of the SonarQube scan in a job ran by our CI/CD. I would like to have some advices on how to make make reproducible successful scans.

  • Use SonarQube Data Center
  • CFamily plugin version: 6.62.0.78645
06:56:17.609 INFO  Sensor CFamily [cpp]
06:56:17.650 INFO  CFamily plugin version: 6.62.0.78645 (829eaa25b0b1054f587bbeeb168e51409c72f905)
06:56:17.651 INFO  CFamily analysis configuration mode: Compile-Commands
06:56:17.655 INFO  Using compile commands: /builds/axiscode/ak/apps/map-core/build/compile_commands.json
06:56:17.657 INFO  Available processors: 16
06:56:17.657 INFO  Using 16 threads for analysis.
06:56:17.657 DEBUG Unpacking analyzer to: /builds/axiscode/ak/apps/map-core/.scannerwork/.sonartmp/15007215938179242002
06:56:20.307 INFO  Loading cache from: server
06:56:20.345 DEBUG Shutting down the worker
06:56:20.346 INFO  Rule                          | Time (ms) | Relative
06:56:20.347 INFO  :-----------------------------|----------:|--------:
06:56:20.347 INFO  internal-symbol-highlighting  |    12.652 |    49.8%
06:56:20.347 INFO  internal-cognitive-complexity |     9.241 |    36.4%
06:56:20.347 INFO  S1607                         |     1.842 |     7.3%
06:56:20.347 INFO  S2699                         |     0.409 |     1.6%
06:56:20.347 INFO  S5863                         |     0.347 |     1.4%
06:56:20.347 INFO  S6092                         |     0.223 |     0.9%
06:56:20.347 INFO  S6080                         |     0.157 |     0.6%
06:56:20.347 INFO  S5973                         |     0.123 |     0.5%
06:56:20.347 INFO  S6079                         |     0.113 |     0.4%
06:56:20.347 INFO  S2486                         |     0.067 |     0.3%
06:56:20.347 INFO  S2187                         |     0.063 |     0.2%
06:56:20.347 INFO  S5958                         |     0.044 |     0.2%
06:56:20.347 INFO  S3415                         |     0.038 |     0.2%
06:56:20.347 INFO  S2970                         |     0.037 |     0.1%
06:56:20.347 INFO  S6426                         |     0.036 |     0.1%
06:56:20.367 DEBUG The worker thread exited with code 0
06:56:20.368 DEBUG The bridge server shut down
06:56:20.369 INFO  Rule | Time (ms) | Relative
06:56:20.369 INFO  :----|----------:|--------:
06:56:20.435 ERROR Error during SonarScanner Engine execution
java.lang.NullPointerException: null
	at java.base/java.util.Objects.requireNonNull(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 java.base/jdk.internal.platform.CgroupUtil.lambda$readStringValue$1(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/jdk.internal.platform.CgroupUtil.readStringValue(Unknown Source)
	at java.base/jdk.internal.platform.CgroupSubsystemController.getStringValue(Unknown Source)
	at java.base/jdk.internal.platform.CgroupSubsystemController.getLongValue(Unknown Source)
	at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.getLongValue(Unknown Source)
	at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.getHierarchical(Unknown Source)
	at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.initSubSystem(Unknown Source)
	at java.base/jdk.internal.platform.cgroupv1.CgroupV1Subsystem.getInstance(Unknown Source)
	at java.base/jdk.internal.platform.CgroupSubsystemFactory.create(Unknown Source)
	at java.base/jdk.internal.platform.CgroupSubsystemFactory.create(Unknown Source)
	at java.base/jdk.internal.platform.CgroupMetrics.getInstance(Unknown Source)
	at java.base/jdk.internal.platform.SystemMetrics.instance(Unknown Source)
	at java.base/jdk.internal.platform.Metrics.systemMetrics(Unknown Source)
	at java.base/jdk.internal.platform.Container.metrics(Unknown Source)
	at jdk.management/com.sun.management.internal.OperatingSystemImpl.<init>(Unknown Source)
	at jdk.management/com.sun.management.internal.PlatformMBeanProviderImpl.getOperatingSystemMXBean(Unknown Source)
	at jdk.management/com.sun.management.internal.PlatformMBeanProviderImpl$3.nameToMBeanMap(Unknown Source)
	at java.management/sun.management.spi.PlatformMBeanProvider$PlatformComponent.getMBeans(Unknown Source)
	at java.management/java.lang.management.ManagementFactory.getPlatformMXBean(Unknown Source)
	at java.management/java.lang.management.ManagementFactory.getOperatingSystemMXBean(Unknown Source)
	at com.sonar.cpp.plugin.MemoryMonitor.finishedAnalysisSetup(MemoryMonitor.java:82)
	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:216)
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:190)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:64)
	at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:226)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:205)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:201)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:197)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:170)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:226)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:205)
	at org.sonar.scanner.bootstrap.SpringScannerContainer.doAfterStart(SpringScannerContainer.java:350)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:226)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:205)
	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:142)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:226)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:205)
	at org.sonar.scanner.bootstrap.ScannerMain.runScannerEngine(ScannerMain.java:151)
	at org.sonar.scanner.bootstrap.ScannerMain.run(ScannerMain.java:66)
	at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:52)
06:56:20.437 DEBUG Cleanup org.eclipse.jgit.util.FS$FileStoreAttributes$$Lambda$393/0x00007fa29034c3f8@764cba during JVM shutdown
06:56:20.797 DEBUG Java command exited with code 1

Hi,

Welcome to the community!

Could we have the full analysis log starting from the analysis command itself?

And, you say the failure is random. Does that mean that sometimes analysis of the project succeeds and then sometimes that same project fails with this error?

 
Thx,
Ann

Yes. Sometimes it fails with this error.

Find attached a file containing: full logs (with some edits) + command-line used + project .properties files:

SonarQubeLogs.txt (136.8 KB)

Hi,

Thanks for the logs. I’ve flagged this for the language experts.

 
Ann

Hello,

This issue appears to be linked to a known OpenJDK bug.

As a workaround, please update your system’s OpenJDK to version 18 or later, and add the analysis parameter sonar.scanner.skipJreProvisioning=true to use your system JRE instead of the bundled one.

Don’t hesitate to reach out if you have any further questions.

1 Like

Hello,

We are currently having the same/similar issue (java.lang.NullPointerException: null). The difference is that the issue is always occurring (not randomly).

We were also using Java 17 and after updating to java 21 we still get the same.

Do you have any idea why this might happen?

In attachment I send the log of the sonar scan and the properties file.
NullExcept.zip (5.4 KB)

Important to note that this issue was not occurring with CFamily 6.41.2.69583.

I also bumped the sonarscanner version to 7.1 and it didn’t work

Thank you in advance.

Hi @MarcoDomingues,

Welcome to the community!

You upgraded Java. Did you add the sonar.scanner.skipJreProvisioning parameter?

 
Ann

Hello.

Yes I did, and it confirms on the build log that it is using java 21.

Hi,

I believe you may be jumping the gun on Java 21. Can you try 17?

 
Ann

We were actually using Java 17 before. I changed to 21 based on the comment of Mostafa Mohammed saying to update to version 18 or later.

It was also not working with Java 17.

Hi @MarcoDomingues,

Having now actually looked at your logs, yours is a different error. Please create a new thread.

 
Ann

1 Like

Hi,

Some feedbacks:

  • Changing the OpenJDK version didn’t solved the issue.
  • After more investigation, the gitlab runners on which sonar-scanner were running had different configurations: some with docker setup with Cgroup V1, others with Cgroup v2. Aligning them to use Cgroup v2 fixed the issue.

As a conclusion, OpenJDK wasn’t the issue. If sonar-scanner is ran in docker, it is not compatible with cgroup v1 and it requires cgroup v2.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.