VScode sonarlint StringIndexOutOfBoundsException when "File" has no extension

I get an StringIndexOutOfBoundsException in sonarlint in vscode when a file without extension exist in the compile_commands.json file. Example file:

[
  {
    "directory": "C:\\Temp\\test",
    "command": "/Xilinx/Vitis/2021.2/gnu/aarch64/nt/aarch64-none/bin\\aarch64-none-elf-gcc -O3 -g3 -std=gnu11 -o test.o test.c",
    "file": "test.c",
    "output": "test.o"
  },
  {
    "directory": "C:\\Temp\\test",
    "command": "echo test",
    "file": "C:/Temp/test/Makefile",
    "output": "C:/Temp/test/Makefile"
  }
]

If I open test.c in vscode I get the exception below, if I rename Makefile to Makefile.txt (or any extension) in file it starts to work.

[Info  - 14:23:24.473] Parsing compilation database c:\Temp\test\compile_commands.json
[Error - 14:23:24.473] Error executing sensor: 'CFamily'
[Error - 14:23:24.473] java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 8
	at java.base/java.lang.String.checkBoundsBeginEnd(Unknown Source)
	at java.base/java.lang.String.substring(Unknown Source)
	at com.sonar.cpp.plugin.SonarLintSensor.getFileNameWithoutExtension(SonarLintSensor.java:251)
	at com.sonar.cpp.plugin.SonarLintSensor.lambda$fillCapturesMaps$2(SonarLintSensor.java:264)
	at com.sonar.cpp.plugin.CompileCommandsReader.readCaptures(CompileCommandsReader.java:46)
	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)

vscode version: 1.66.1
sonarlint version: 3.4.0

Hello @motoz,

Thanks for your report.

Yes, you are right. We assumed that inside the compilation database, there should be compiled files that have extensions.

We will relax this requirement in the next release. You can expect a fix in the 3-4 weeks.
Until then, you can drop those entries with no file extension from the compilation database to unblock the analysis.

Here is the ticket: [CPP-3653] Improve VS Code Parsing and logging of compilation database - SonarSource

Let me know if you face other problems.

Thanks,

1 Like

Hello @motoz,
this should be solved in the latest SonarLint for VS Code release
Thanks,

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