`-include` treated as PCH and failing to be analyzed

We make use of the -include parameter of gcc/clang and have a simple header file added before each file for compilation. SonarQube is able to analyze all files with -include in the compile command, but after that phase it treats the special include file as an PCH and trips on it.

With the compile command similar to this:

g++ -include <project>/pre_include.h file.cpp

analysis of file.cpp succeeds (albeit wrongly flags use of PCH in the debug statements)

15:39:13.298 INFO  [thread-1] Started analyzing: <project>/file.cpp
15:39:13.731 DEBUG [pool-6-thread-1] <project>/file.cpp: using PCH
15:39:13.731 DEBUG [pool-6-thread-1] <project>/file.cpp: building PCH
15:39:13.756 INFO  [1/1] Finished analyzing: <project>/file.cpp (430ms)

but then proceeds to analyse PCH and fails.

15:39:13.757 INFO  Starting the analysis of 1 extra PCH compilation units
15:39:13.757 DEBUG Cache miss for <project>/pre_include.h: file not in cache
15:39:13.757 INFO  [thread-2] Started analyzing: <project>/pre_include.h
15:39:13.805 ERROR Exception in thread pool-6-thread-2
java.lang.NullPointerException: file can't be null
	at java.base/java.util.Objects.requireNonNull(Unknown Source)
	at org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable.onFile(DefaultSymbolTable.java:55)
	at org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable.onFile(DefaultSymbolTable.java:39)
	at com.sonar.cpp.plugin.AnalysisResult.saveSymbols(AnalysisResult.java:251)
	at com.sonar.cpp.plugin.AnalysisResult.save(AnalysisResult.java:198)
	at com.sonar.cpp.plugin.CFamilySensor.lambda$process$10(CFamilySensor.java:760)
	at com.sonar.cpp.analyzer.AnalysisExecutor.lambda$submit$0(AnalysisExecutor.java:58)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

15:39:13.863 DEBUG Java memory after analysis is done (used, peak): 124MB, 124MB
15:39:13.889 ERROR Error during SonarScanner Engine execution
java.lang.IllegalStateException: java.lang.NullPointerException: file can't be null
	at com.sonar.cpp.analyzer.AnalysisExecutor.drain(AnalysisExecutor.java:83)
	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:612)
	at com.sonar.cpp.plugin.CFamilySensor.processConfigurationReader(CFamilySensor.java:474)
	at com.sonar.cpp.plugin.CFamilySensor.lambda$process$2(CFamilySensor.java:234)
	at java.base/java.lang.Iterable.forEach(Unknown Source)
	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:234)
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:182)
	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:204)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:200)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:173)
	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:351)
	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:144)
	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:149)
	at org.sonar.scanner.bootstrap.ScannerMain.run(ScannerMain.java:66)
	at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:52)
Caused by: java.lang.NullPointerException: file can't be null
	at java.base/java.util.Objects.requireNonNull(Unknown Source)
	at org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable.onFile(DefaultSymbolTable.java:55)
	at org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable.onFile(DefaultSymbolTable.java:39)
	at com.sonar.cpp.plugin.AnalysisResult.saveSymbols(AnalysisResult.java:251)
	at com.sonar.cpp.plugin.AnalysisResult.save(AnalysisResult.java:198)
	at com.sonar.cpp.plugin.CFamilySensor.lambda$process$10(CFamilySensor.java:760)
	at com.sonar.cpp.analyzer.AnalysisExecutor.lambda$submit$0(AnalysisExecutor.java:58)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

15:39:13.891 DEBUG Cleanup org.eclipse.jgit.util.FS$FileStoreAttributes$$Lambda$364/0x00000008003b6420@3d6a6bee during JVM shutdown
15:39:14.289 DEBUG Java command exited with code 1
15:39:14.289 INFO  EXECUTION FAILURE

Looks like the scanner wrongly assumes the file provided with -include is a PCH.

SonarQube: v10.6
SonarScanner CLI 6.1.0.4477

Hello @mejdys.adyen ,

This will be fixed in SonarQube 10.7

https://sonarsource.atlassian.net/browse/CPP-5701

In the meantime, and to unlock your analysis, you can add the following property to your configuration:

sonar.cfamily.internal.usePCH=false

Please, let me know if this helps.

Thanks for the quick reaction and a good tip. This workaround works for us. Looking forward to SonarQube 10.7!

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