SonarScanner fails with java exception when using compilation database instead of build wrapper logs

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension):
    SonarQube Developer Edition Version 9.0 (build 45539)
    SonarScanner 4.6.2.2472
    Java 11.0.12 Homebrew (64-bit)
    Mac OS X 11.6.2 x86_64
    CMake 3.21.4

  • what are you trying to achieve
    switch from build wrapper to compilation database because of missing wrapper support for Apple silicon CPUs

  • what have you tried so far to achieve this
    Switched the source of compile information

Hi, we introduced an M1 mac to our build infrastructure. As there is no support for the build wrapper for Apple Silicon, we need to switch to the compilation database generated by cmake. When doing this, the sonar-scanner errors out with a Java exception:

15:18:41   15:18:41.246 ERROR: Error during SonarQube Scanner execution
15:18:41   java.lang.IllegalStateException: java.io.IOException: Is a directory
15:18:41     at com.sonar.cpp.plugin.CompileCommandsReader.readCaptures(CompileCommandsReader.java:44)
15:18:41     at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:575)
15:18:41     at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:387)
15:18:41     at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:173)
15:18:41     at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
15:18:41     at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
15:18:41     at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
15:18:41     at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:79)
15:18:41     at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
15:18:41     at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
15:18:41     at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:382)
15:18:41     at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:378)
15:18:41     at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:347)
15:18:41     at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
15:18:41     at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
15:18:41     at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:136)
15:18:41     at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
15:18:41     at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
15:18:41     at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
15:18:41     at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
15:18:41     at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
15:18:41     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:18:41     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
15:18:41     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:18:41     at java.base/java.lang.reflect.Method.invoke(Method.java:566)
15:18:41     at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
15:18:41     at com.sun.proxy.$Proxy0.execute(Unknown Source)
15:18:41     at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
15:18:41     at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
15:18:41     at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
15:18:41     at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
15:18:41     at org.sonarsource.scanner.cli.Main.main(Main.java:61)
15:18:41   Caused by: java.io.IOException: Is a directory
15:18:41     at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method)
15:18:41     at java.base/sun.nio.ch.FileDispatcherImpl.read(FileDispatcherImpl.java:48)
15:18:41     at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
15:18:41     at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:245)
15:18:41     at java.base/sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:223)
15:18:41     at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
15:18:41     at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
15:18:41     at java.base/sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
15:18:41     at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
15:18:41     at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
15:18:41     at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
15:18:41     at java.base/java.io.InputStreamReader.read(InputStreamReader.java:181)
15:18:41     at java.base/java.io.BufferedReader.fill(BufferedReader.java:161)
15:18:41     at java.base/java.io.BufferedReader.read1(BufferedReader.java:212)
15:18:41     at java.base/java.io.BufferedReader.read(BufferedReader.java:287)
15:18:41     at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1291)
15:18:41     at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1329)
15:18:41     at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:550)
15:18:41     at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:344)
15:18:41     at com.sonar.cpp.plugin.CompileCommandsReader.readCaptures(CompileCommandsReader.java:37)
15:18:41     ... 31 more
15:18:41   Process exited with code 1

does anyone else have a similar experience or does anyone know what could cause this issue and how this could be solved? Also the debug information with -X doesn’t give any additional information about it.

Content of the sonar scanner properties file:

sonar.projectKey=XXXXXX
sonar.sources=XXXXX
sonar.exclusions= XXXXXX
sonar.host.url=XXXXXX
sonar.branch.name=master
sonar.login=XXXXXXX
sonar.cfamily.compile-commands=compile_commands.json
sonar.sourceEncoding=UTF-8
sonar.cfamily.threads=2
sonar.cfamily.cache.enabled=false
sonar.qualitygate.wait=true

Hi @the_frank ,

According to this line in the log, you are pointing sonar.cfamily.compile-commands to a directory and not to a file, compile_commands.json should be a json file.

hmmm…checking the build directory content and it turned out that teamcity flagged the file as a directory. I think I fixed it now, thx.

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