NullPointerException while probing compiler when build was run with clang-tidy

sonarcfamily
(Simon Giesecke) #1

There is a NullPointerException while probing the compiler in sonar-scanner when the build was run with clang-tidy. Obviously, the arguments do not fit for clang-tidy, but only for the “real” compiler. However, I don’t know where sonar-scanner exactly gets the information on the compiler executable.

Template for a good bug report, formatted with Markdown:

10:32:21.525 DEBUG: Probing compiler: [/usr/lib/llvm-7/bin/clang-tidy, -x, c++, --std, gnu++11, -v, -dM, -E, -]
10:32:21.550 DEBUG: stdout:
10:32:21.550 DEBUG: stderr:
LLVM ERROR: CommonOptionsParser: failed to parse command-line arguments. [CommonOptionsParser]: clang-tidy: Unknown command line argument '-x'.  Try: '/usr/lib/llvm-7/bin/clang-tidy -help'
clang-tidy: Did you mean '-h'?
clang-tidy: Unknown command line argument '--std'.  Try: '/usr/lib/llvm-7/bin/clang-tidy -help'
clang-tidy: Did you mean '-h'?
clang-tidy: Unknown command line argument '-v'.  Try: '/usr/lib/llvm-7/bin/clang-tidy -help'
clang-tidy: Did you mean '-h'?
clang-tidy: Unknown command line argument '-dM'.  Try: '/usr/lib/llvm-7/bin/clang-tidy -help'
clang-tidy: Did you mean '-h'?
clang-tidy: Unknown command line argument '-E'.  Try: '/usr/lib/llvm-7/bin/clang-tidy -help'
clang-tidy: Did you mean '-h'?
10:32:21.655 INFO: ------------------------------------------------------------------------
10:32:21.656 INFO: EXECUTION FAILURE
10:32:21.657 INFO: ------------------------------------------------------------------------
10:32:21.659 INFO: Total time: 53.871s
10:32:21.823 INFO: Final Memory: 25M/208M
10:32:21.823 INFO: ------------------------------------------------------------------------
10:32:21.823 ERROR: Error during SonarQube Scanner execution
java.lang.NullPointerException
	at com.sonar.cpp.analyzer.StdFlags.fromCppMacros(StdFlags.java:23)
	at com.sonar.cpp.analyzer.ClangDriver.onCapture(ClangDriver.java:332)
	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:266)
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:198)
	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:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:367)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:362)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:325)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:130)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	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:185)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
(Massimo Paladin) #2

Hi @sigiesec,

thank you for your report, I created a ticket on dev side: CPP-2106.
While waiting for the fix you can split clang-tidy and SonarCloud analysis in 2, if you disable clang-tidy you are not supposed to get the failure anymore.

(Nikhil Patil) #3

Hi Massimo,

I am new to Sonar and I am facing same issue as above.
From your above post I understand i have to disable clang-tidy.
Can you please suggest me how to split clang-tidy and SonarCloud and disable clang-tidy.
Can you please help me on this.

(Massimo Paladin) #4

Hi @Nikhil_Patil,

I don’t know the setup of your project so I am not sure how I can help you on that.

(Nikhil Patil) #5

Hi Massimo,

Thanks for the reply, as suggested please find the details below.

We have installed Sonar-7.2 Commercial edition on Linux machine and we are running
“build-wrapper-win-x86-64 --out-dir bw-outputs app-build.bat” on our local machine with “sonar-project.properties” file and this is running successfully and it is generation the “build-wrapper-dump.json” file.
Post this when we run “sonar-scanner” command we are getting the Null pointer Exception as below

Error during SonarQube Scanner execution
java.lang.NullPointerException
at com.sonar.cpp.analyzer.StdFlags.fromCppMacros(StdFlags.java:23)
at com.sonar.cpp.analyzer.ClangDriver.onCapture(ClangDriver.java:332)
at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:266)
at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:198)
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:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:408)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:403)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:360)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
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:185)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)

(Massimo Paladin) #6

Hi @Nikhil_Patil,

I would suggest you to open a new thread for your request.
In any case you would need to remove the clang-tidy invocation from your build build.bat script.