SonarScanner MsvcDriver crashes when analysing

SonarQube Version: 8.9.1 (build 44547)
SonarScanner Version: 4.6.2.2472

Our build setup uses FastBuild together with the Visual Studio Build Tools to compile our codebase.

Since SonarQube 8.9 (LTS) does not support generation of the build wrapper based on a Compilation Database yet, I used the conversion script workaround mentioned on JIRA.

When running the sonarscanner on the converted build-wrapper-dump.json, I get a NullPointerException at com.sonar.cpp.analyzer.MsvcDriver.onCapture (MsvcDriver.java:240) (see full crash log below) - after successfully generating the metadata.

What would cause such an exception?

I cannot share the entire logs due to the proprietary nature of the project. If you need specific information, please let me know and I’ll and share if possible.

These are all supported SonarQube plugins:

  - CSS Code Quality and Security 1.4.2.2002 (cssfamily)
  - PL/SQL Code Quality and Security 3.6.1.3873 (plsql)
  - Scala Code Quality and Security 1.8.3.2219 (sonarscala)
  - C# Code Quality and Security 8.22.0.31243 (csharp)
  - Vulnerability Analysis 8.9.0.11439 (security)
  - Java Code Quality and Security 6.15.1.26025 (java)
  - HTML Code Quality and Security 3.4.0.2754 (web)
  - Flex Code Quality and Security 2.6.1.2564 (flex)
  - XML Code Quality and Security 2.2.0.2973 (xml)
  - VB.NET Code Quality and Security 8.22.0.31243 (vbnet)
  - Swift Code Quality and Security 4.3.1.4892 (swift)
  - CFamily Code Quality and Security 6.20.1.32841 (cpp)
  - Python Code Quality and Security 3.4.1.8066 (python)
  - Go Code Quality and Security 1.8.3.2219 (go)
  - JaCoCo 1.1.1.1157 (jacoco)
  - Kotlin Code Quality and Security 1.8.3.2219 (kotlin)
  - RPG Code Quality 2.5.1.2575 (rpg)
  - PL/I Code Quality and Security 1.11.1.2727 (pli)
  - T-SQL Code Quality and Security 1.5.1.4340 (tsql)
  - VB6 Code Quality and Security 2.7.1.2721 (vb)
  - Apex Code Quality and Security 1.8.3.2219 (sonarapex)
  - JavaScript/TypeScript Code Quality and Security 7.4.4.15624 (javascript)
  - Ruby Code Quality and Security 1.8.3.2219 (ruby)
  - Vulnerability Rules for C# 8.9.0.11439 (securitycsharpfrontend)
  - Vulnerability Rules for Java 8.9.0.11439 (securityjavafrontend)
  - License for SonarLint 8.9.1.44547 (license)
  - Vulnerability Rules for JS 8.9.0.11439 (securityjsfrontend)
  - COBOL Code Quality 4.6.2.4876 (cobol)
  - Vulnerability Rules for Python 8.9.0.11439 (securitypythonfrontend)
  - PHP Code Quality and Security 3.17.0.7439 (php)
  - ABAP Code Quality and Security 3.9.1.3127 (abap)
  - Vulnerability Rules for PHP 8.9.0.11439 (securityphpfrontend)

Crash log:

09:40:11.597 DEBUG: stylelint-bridge server will shutdown
09:40:16.638 INFO: ------------------------------------------------------------------------
09:40:16.638 INFO: EXECUTION FAILURE
09:40:16.638 INFO: ------------------------------------------------------------------------
09:40:16.638 INFO: Total time: 37.152s
09:40:16.737 INFO: Final Memory: 38M/176M
09:40:16.737 INFO: ------------------------------------------------------------------------
09:40:16.738 ERROR: Error during SonarScanner execution
java.lang.NullPointerException
        at com.sonar.cpp.analyzer.MsvcDriver.onCapture(MsvcDriver.java:240)
        at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:584)
        at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:367)
        at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:175)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:392)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:388)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:357)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:150)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Hi @remcok ,

could you share the entire log and the build-wrapper output folder content if I send you a private message?

Hi @mpaladin,

Sadly I’d still not be able to share those unless I redacted pretty much everything in the file.

I was able to narrow down the cause on my end. If I swap out the path of the executable of all captures, SonarScanner does not throw an exception. It seems that - even though the executables exist for all captures - some permissions are set incorrectly.

If that sparks any ideas, please let me know.

Hi @remcok ,

unfortunately without the logs I cannot help you much, and it is not a good idea to change the build-wrapper-dump.json file as you may get an incorrect and unintended analysis.

That’s unfortunate.

Based on the call stack that I provided, would you at least be able to share what is a causing the null pointer exception? E.g. can the SonarScanner not find the executable, or does it not have permission to run it?

Hi @remcok ,

I can see what is causing the stack trace and I would need the debug log to give a better hint, instead of just starting to guess.

I was able to solve the issue by including a capture of the msvc-cl that ran with no command-line arguments and returns an stdout and stderr, like such:

It seems that SonarScanner is looking through the build-wrapper-dump.json's captures for an entry that has an stderr, which is then used to determine the Compiler Version. If it’s missing, it throws the NullPointerException that I was seeing.

Hi @remcok ,

I just want to state that it is not supported to modify build-wrapper-dump.json content, this is a workaround, you are not fixing the real issue which is still unknown.

As stated in the original question, we are manually generating the build-json-wrapper.json as a workaround

Since SonarQube 8.9 (LTS) does not support generation of the build wrapper based on a Compilation Database yet, I used the conversion script workaround mentioned on JIRA.

This is a workaround recommended by SonarQube devs, which only works - for us - with the amendments made to the script that I listed in the solution. As such, it does solve the real issue.

Hi @remcok ,

I indeed missed or forgot about this point, sorry about that. Then fine to add the probe manually as you did.

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