sonarQube fails on file path too long 261 characters on windows

We get the an llegalStateException exception on Windows 10 Enterprise. ( see sonar-scanner output section bellow ) when parsing a file that as a very long path.

The string that fails as exactly 261 characters which is 1 more then the typical limit of a shell.
It actually is the second time we get this problem, the first time we did a temporary fix by getting rid of a couple of characters in some folders.

I tried setting
Set-ItemProperty ‘HKLM:\System\CurrentControlSet\Control\FileSystem’ -Name ‘LongPathsEnabled’ -value 1
In a powershell and then calling manually sonar-scanner.bat but I get the same error.
I’m trying to call java directly from powershell not from the batch file with the following powershell script but I it fails with : java.lang.ClassNotFoundException: org.sonarsource.scanner.cli.Main error.

And I think I might be beating a dead horse here.

$java="C:\Program Files\Common Files\Oracle\Java\javapath\java.exe" 
$cp='-cp' 
$cli='C:\agent\_work\_tasks\SonarQubeAnalyze6d01813a-9589-4b15-8491-8164aeb38055\4.31.0\sonar-scanner\bin\..\lib\sonar-scanner-cli-4.7.0.2747.jar'
$scanhome='-Dscanner.home=C:\agent\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.31.0\sonar-scanner\bin\..'
$prjhome='-Dproject.home=C:\agent\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.31.0\sonar-scanner\bin'
$main='org.sonarsource.scanner.cli.Main'

& $java $cp $cli $scanhome $prjhome $main

Any hints or guide lines would be appreciated to figure out where I should search to get the shell or java to support more then 260 characters.

Thansks

sonar-scanner output

2022-09-30T19:56:25.0864618Z ##[section]Starting: SonarQube Analysis
2022-09-30T19:56:25.1072207Z ==============================================================================
2022-09-30T19:56:25.1072467Z Task : Run Code Analysis
2022-09-30T19:56:25.1072682Z Description : Run scanner and upload the results to the SonarQube server.
2022-09-30T19:56:25.1072880Z Version : 4.31.0
2022-09-30T19:56:25.1073028Z Author : sonarsource
2022-09-30T19:56:25.1073422Z Help : Version: 4.31.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

More Information
2022-09-30T19:56:25.1073857Z ==============================================================================
2022-09-30T19:56:25.3319256Z [command]C:\WINDOWS\system32\cmd.exe /D /S /C “C:\agent_work_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.31.0\sonar-scanner\bin\sonar-scanner.bat”
2022-09-30T19:56:25.4923683Z INFO: Scanner configuration file: C:\agent_work_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\4.31.0\sonar-scanner\bin..\conf\sonar-scanner.properties
2022-09-30T19:56:25.4927103Z INFO: Project root configuration file: C:\agent_work\2\s\sonar-project.properties
2022-09-30T19:56:25.5290302Z 15:56:25.520 INFO: SonarScanner 4.7.0.2747
2022-09-30T19:56:25.5290761Z 15:56:25.528 INFO: Java 11.0.12 Oracle Corporation (64-bit)
2022-09-30T19:56:25.5291041Z 15:56:25.528 INFO: Windows 10 10.0 amd64
2022-09-30T19:56:25.5292726Z 15:56:25.528 INFO: SONAR_SCANNER_OPTS=“-Djavax.net.ssl.trustStore=C:\Program Files\Java\jdk-17.0.1\lib\security\cacerts -Djavax.net.ssl.keyStore=C:\Program Files\Java\jdk-17.0.1\lib\security\cacerts”



java.lang.IllegalStateException: c:\st\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\bin../lib/gcc/arm-none-eabi/10.3.1/…/…/…/…/arm-none-eabi/include/c++/10.3.1/arm-none-eabi/thumb/v7-m/nofp\bits/c++allocator.h
at com.sonar.cpp.jni.FileSystemOperations.realPath(FileSystemOperations.java:51)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
at com.sonar.cpp.fs.CanonicalPathCache.computeIfAbsent(CanonicalPathCache.java:17)
at com.sonar.cpp.plugin.CFamilySensor.lambda$save$15(CFamilySensor.java:824)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
at com.sonar.cpp.plugin.CFamilySensor.save(CFamilySensor.java:824)
at com.sonar.cpp.plugin.CFamilySensor.lambda$process$14(CFamilySensor.java:798)
at com.sonar.cpp.analyzer.AnalysisExecutor.lambda$submit$0(AnalysisExecutor.java:59)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
2022-09-30T19:56:56.5689142Z 15:56:56.564 ERROR: Exception in thread pool-3-thread-1

Hi,

Welcome to the community!

There’s a lot going on here that I don’t understand.

Leaving aside the 53-char job name(?!), it seems that you’re downloading your project for analysis into the sonar-scanner directory…?

$scanhome='-Dscanner.home=C:\agent\_work\_tasks\...\4.31.0\sonar-scanner\bin\..'
$prjhome='-Dproject.home=C:\agent\_work\_tasks\...\4.31.0\sonar-scanner\bin'

And also, you shouldn’t need to invoke Java directly or the jar itself. Invoke the scanner script, and assuming you’ve downloaded the right version & followed the directions the script will take care of it.

Those docs I just pointed you to will also help you with the correct property names and which ones you need.

Thanks for the reply,
I reverted the code I was trying to do run in powershell and I’m using the original configuration.
I believe that scanhome and prjhome folders pointing in the wrong folders are artefacts of me trying stuff out

The real problem seems to be when we scan
c:\st\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\bin…/lib/gcc/arm-none-eabi/10.3.1/…/…/…/…/arm-none-eabi/include/c++/10.3.1/arm-none-eabi/thumb/v7-m/nofp\bits/c++allocator.h

Which is exactly 261 character long path. And these paths are installed/generated by stm32CubeIde so I have very little control on there installation path. Is there a way to get around the 260 character limit when scanning ?

I’ll try to see if I can shorten the path but the feels more like a patch then a true fix. And at first glance I believe I only have control over parts of the path “c:\st\stm32cubeide”

regards
Nathaniel