VS Code Sonarlint plugin: Error executing sensor: 'CFamily'

Description

I use Visual Studio Code together with the IAR Embedded Compilers. After setting SonarLint up in in Connected Mode according to instructions in Marketplace, I get the error Error executing sensor: ‘CFamily’ in SonarLint output.

Versions

I use the following tools/versions:

  • SonarQube: Enterprise Edition Version 8.9.7 (build 52159)

  • SonarLint: 3.4.0

  • Visual Studio Code: 1.66.0

  • IAR C/C++ Compiler for ARM: 9.20.4.327

  • Java: OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)

SonarLint Output

[Debug - 11:36:52.678] Start analysis
[Info - 11:36:52.686] Index files
[Debug - 11:36:52.687] Language of file 'file:///c:/Projekte/limulus/src/itc/ITCFramework.cpp' is set to 'C++'
[Info - 11:36:52.690] 1 file indexed
[Debug - 11:36:52.695] Loading C:\Users\102-anmu\AppData\Local\Temp\sonarsource-cfamily-jni13307686884390603175.dll
[Debug - 11:36:52.861] 'JavaSquidSensor' skipped because there is no related files in the current project
[Debug - 11:36:52.861] Execute Sensor: CFamily
[Debug - 11:36:52.863] Unpacking analyzer to: C:\Users\102-anmu\.sonarlint\work\.sonartmp_16605804904575216633\2115453303497960910
[Info - 11:36:54.571] Parsing compilation database c:\Projekte\limulus\compile_commands.json
[Error - 11:36:54.609] Error executing sensor: 'CFamily'
[Error - 11:36:54.610] java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Unknown Source)
at java.base/sun.nio.fs.WindowsFileSystem.getPath(Unknown Source)
at java.base/java.nio.file.Path.of(Unknown Source)
at java.base/java.nio.file.Paths.get(Unknown Source)
at com.sonar.cpp.analyzer.DriverUtil.absolute(DriverUtil.java:30)
at com.sonar.cpp.plugin.CompileCommandsReader.getCapture(CompileCommandsReader.java:95)
at com.sonar.cpp.plugin.CompileCommandsReader.readCaptures(CompileCommandsReader.java:45)
at com.sonar.cpp.plugin.SonarLintSensor.fillCapturesMaps(SonarLintSensor.java:260)
at com.sonar.cpp.plugin.SonarLintSensor.parseCompileCommands(SonarLintSensor.java:229)
at com.sonar.cpp.plugin.SonarLintSensor.processCompileCommands(SonarLintSensor.java:139)
at com.sonar.cpp.plugin.SonarLintSensor.process(SonarLintSensor.java:131)
at com.sonar.cpp.plugin.SonarLintSensor.execute(SonarLintSensor.java:94)
at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:169)
at org.sonarsource.sonarlint.core.analysis.container.analysis.sensor.SensorsExecutor.executeSensor(SensorsExecutor.java:81)
at org.sonarsource.sonarlint.core.analysis.container.analysis.sensor.SensorsExecutor.execute(SensorsExecutor.java:72)
at org.sonarsource.sonarlint.core.analysis.container.analysis.AnalysisContainer.doAfterStart(AnalysisContainer.java:122)
at org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer.startComponents(ComponentContainer.java:119)
at org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer.execute(ComponentContainer.java:104)
at org.sonarsource.sonarlint.core.analysis.container.module.ModuleContainer.analyze(ModuleContainer.java:71)
at org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand.execute(AnalyzeCommand.java:58)
at org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand.execute(AnalyzeCommand.java:32)
at org.sonarsource.sonarlint.core.analysis.AnalysisEngine$AsyncCommand.execute(AnalysisEngine.java:152)
at org.sonarsource.sonarlint.core.analysis.AnalysisEngine.executeQueuedCommands(AnalysisEngine.java:70)
at java.base/java.lang.Thread.run(Unknown Source)
[Debug - 11:36:54.610] 'Apex Sensor' skipped because there is no related files in the current project

Hello @mulleand,

It looks like it is failing while we are looking for the file entry in your compilation database. We expect it to be there.
Can you share the content of your compilation database and the full logs?

Let me know if you prefer to share them privately.

Hi Abbas_Sabra

Thanks for you quick reply: I’m happy to provide additional logs but I would prefer to do so privately.

Hi @mulleand,

Can you enable analyzer logs and reshare them.
you can enable them from the UI or from the settings.json file
"sonarlint.output.showAnalyzerLogs": true,

Thanks,

Hi @Abbas_Sabra

I had this option already enabled. Where would I find this output if it were missing from the provided logs? Sorry I am new to SonarLint in VS Code.

Hello @mulleand,

I had a look at your compilation database and it is invalid.
Every entry should have the three mandatory fields: file, directory, and command/arguments. These three are mandatory according to the documentation.

If you drop the last entry from your compilation database that contains “files” instead of “file”(Linker entry) the analysis should work.

Your compilation database doesn’t look standard(JSON Compilation Database Format Specification — Clang 15.0.0git documentation) since it contains “type”. That shouldn’t be an issue as long as every entry contains the mandatory fields. Out of curiosity how are you generating this compilation database?

I created a ticket to improve the error message to point you directly to the invalid entry.

Thanks,

Hi @Abbas_Sabra

Thank you very much for this pointer. If I remove this entry, everything works as expected. I generated the compilation database with the IAR Build Tool (iarbuild.exe) and the -jsondb parameter.

I will raise an issue with IAR about the non-standard compilation database.

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