Sonar scanner fails with java.nio.file.InvalidPathException

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    Sonarqube: Version 9.6.1 (build 59531)
    Sonarscanner: 4.6.2.2472

We just run sonar using mvn sonar:sonar in Gitlab CI. I know there’s a 4.7 release for sonar-scanner-cli, but I’m not sure how to bump our version to that as we didn’t configure the version anywhere. I doubt that the 4.7 would fix the issue though.

  • what are you trying to achieve
    Just trying to run Java tests and have sonar analyze the coverage.
  • what have you tried so far to achieve this
    Run sonar using mvn sonar:sonar, we’ll see whether we can ignore the test from sonar for now.

We have a test that tests our encoding so it uses a very fancy file name. It seems like SonarScanner’s git integration can’t handle the filename. The used filename is as follows

EncodingTest/%20 fo%lder/It's$a%30me Mariomariposónمرحبا مارك.ホットドッグが好き/It's$a%30me Mario.vhdl

It contains: spaces, characters that look like they’re already encoded (but that should be encoded once more), Arabic (Left-to-Right), and Japanese katakana, hiragana, and kanji. The error we receive is as follows (the ???? are printed as is in the console)

Caused by: java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: com.sigasi.hdt.exampleprojects/vhdl-projects/EncodingTest/%20 fo%lder/It's$a%30me Mariomaripos?n????? ????.?????????/It's$a%30me Mario.vhdl` `	at java.base/sun.nio.fs.UnixPath.encode(UnixPath.java:145)` `	at java.base/sun.nio.fs.UnixPath.<init>(UnixPath.java:69)` `	at java.base/sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:279)` `	at java.base/java.nio.file.Path.resolve(Path.java:515)` `	at org.sonar.scm.git.GitScmProvider.lambda$branchChangedFiles$1(GitScmProvider.java:135)` `	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)` `	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)` `	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)` `	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)` `	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)` `	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)` `	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)` `	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)` `	at org.sonar.scm.git.GitScmProvider.branchChangedFiles(GitScmProvider.java:136)` `	at org.sonar.scanner.scm.ScmChangedFilesProvider.loadChangedFilesIfNeeded(ScmChangedFilesProvider.java:59)` `	at org.sonar.scanner.scm.ScmChangedFilesProvider.provide(ScmChangedFilesProvider.java:41)` `	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)` `	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)` `	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)` `	at java.base/java.lang.reflect.Method.invoke(Method.java:566)` `	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)` `	... 93 more

Hello,

Thank you for reaching out.

We tried our best to mimic a scan using a similar folder and file name and were able to scan successfully. We are using the exact same version of the scanner, sonarqube, and Postgres (with docker):

I would be curious to know how your Gitlab CI runner is configured, and if the configuration supports UTF-8 encoding. In addition, could you provide a full log of the scanner for us to do a deeper investigation?

Many thanks.