Sonar Scanner fails with InvalidPathException Malformed input or input contains unmappable charactes

description

I’m migrating from SonarSource/sonarcloud-github-c-cpp to onarSource/sonarqube-scan-action/install-build-wrapper and SonarSource/sonarqube-scan-action. I’m hitting this error:

Caused by: java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: /runner/_work/packdb/packdb/contrib/aws-c-common/tests/resources/?? ??xample.txt
	at java.base/sun.nio.fs.UnixPath.encode(Unknown Source)
	at java.base/sun.nio.fs.UnixPath.<init>(Unknown Source)
	at java.base/sun.nio.fs.UnixFileSystem.getPath(Unknown Source)
	at java.base/java.io.File.toPath(Unknown Source)
	at org.sonar.plugins.javascript.analysis.TsConfigProvider$LookupTsConfigProvider.tsconfigs(TsConfigProvider.java:236)
	at org.sonar.plugins.javascript.analysis.TsConfigProvider.tsconfigs(TsConfigProvider.java:125)
	at org.sonar.plugins.javascript.analysis.TsConfigProvider.getTsConfigs(TsConfigProvider.java:99)
	at org.sonar.plugins.javascript.analysis.AnalysisWithProgram.analyzeFiles(AnalysisWithProgram.java:52)
	at org.sonar.plugins.javascript.analysis.JsTsSensor.analyzeFiles(JsTsSensor.java:82)
	at org.sonar.plugins.javascript.analysis.AbstractBridgeSensor.execute(AbstractBridgeSensor.java:71)
	... 22 common frames omitted

14:45:08.620 INFO  EXECUTION FAILURE
14:45:08.621 INFO  Total time: 58.621s

Following our contrib link (git submodule): aws-c-common/tests/resources at 324fd1d973ccb25c813aa747bf1759cfde5121c5 · ClickHouse/aws-c-common · GitHub , file " Å Éxample.txt"

details

Sonar scanner version: sonar-scanner-cli-6.2.1.4610-Linux-X64
Sonar Github Action: SonarSource/sonarqube-scan-action@bfd4e558cda28cda6b5defafb9232d191be8c203 # v4.2.1
Project: C++

Github workflow:

      - name: Install Build Wrapper
        uses: SonarSource/sonarqube-scan-action/install-build-wrapper@bfd4e558cda28cda6b5defafb9232d191be8c203 # v4.2.1
      - uses: ./.github/actions/run-cmake-cmd # internal github workflow to run cmake command
      - name: SonarQube Scan
        uses: SonarSource/sonarqube-scan-action@bfd4e558cda28cda6b5defafb9232d191be8c203 # v4.2.1
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

I tried to add sonar.sourceEncoding=UTF-8 to sonar-project.properties.

questions

How can I fix it?
Is there any recommendation to exclude contrib directories (with lots of git submodules) from the sonar scanner? What’s the sonar team recommendation for it?

Hey @betorvs

Thanks for the report. This matches another report that we received in December.

So far we haven’t been able to reproduce the issue. Are you facing the issue on a self-hosted GitHub Action runner, or one provided from GitHub?

1 Like

It’s a self host runner. Based on Ubuntu 22.04.

After excluding contrib/** in sonar-project.proterties file (sonar.exclusions) it worked. But I’m not sure if this a good solution. Should sonar scan vendors directories like contrib and others?

The analyzer excludes a number of directories by default:

It might make sense to add **/contrib/** there. I’ll flag that and leave that up to our team.

Hello @betorvs,

thanks for reporting this. I agree with @Colin that it makes sense to add contrib to the default exclusions. I created a ticket to handle this.

In any case, not directly related but another possible workaround is to skip altogether the tsconfig.json files lookup (the failure happens while traversing the project tree looking for those files) by providing the property:

sonar.typescript.tsconfigPaths=dir1/tsconfig.json,dir2/tsconfig.json

In that case, the JS/TS analyzer will pick whatever location the user specifies and will not walk the whole project tree.

Cheers,
Victor