Sonar Scanner: Encoded String too long

Info:

  • SonarQube Enterprise Edition, Version 7.9.2 (build 30863), Scanner Version 4.2.0.1873, build-wrapper, version 6.6 (win-x86-64)

Error message:

12:49:44.749 ERROR: Exception in thread pool-1-thread-1
java.lang.IllegalStateException: java.io.UTFDataFormatException: encoded string too long: 197163 bytes
        at com.sonar.cpp.analyzer.Subprocess.execute(Subprocess.java:46)
        at com.sonar.cpp.analyzer.Subprocess.execute(Subprocess.java:33)
        at com.sonar.cpp.plugin.CFamilySensor.lambda$process$5(CFamilySensor.java:498)
        at com.sonar.cpp.analyzer.AnalysisExecutor.lambda$submit$0(AnalysisExecutor.java:53)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.io.UTFDataFormatException: encoded string too long: 197163 bytes
        at java.base/java.io.DataOutputStream.writeUTF(Unknown Source)
        at java.base/java.io.DataOutputStream.writeUTF(Unknown Source)
        at com.sonar.cpp.analyzer.Protocol.write(Protocol.java:32)
        at com.sonar.cpp.analyzer.Subprocess.execute(Subprocess.java:44)
        ... 8 common frames omitted

Steps to reproduce:

  • Have a LOT of macros defined (and i mean 200KB of macro)

Hello,

i encountered this problem while trying to scan a C++ Project with SonarCFamily today. We have a lot of macros in our build environment. I could narrow down the problem to the stdout out line in the build-wrapper-dump.json. By manually adding macros and removing macros i could watch the bytecount in the error message change accordingly. It is not possible for me to leave out any macros and still have a functioning build.

Thanks in advance,
Moritz

Hi @M-Birk,

the exception is indeed linked to the number of macros you are predefining, are those macros defined by command line?
Could you share the build-wrapper-dump.json file so I could have a look?

If it is the case that you are defining too many macros on the command line may I ask you why you are doing that? Why aren’t you placing them in a header file and using -include option to pre-include such header file?

Hi @mpaladin
thanks for the fast reply.
We only define 5 macros by command line. The rest comes from headerfiles and we’ve got a lot of those since its a rather large project.

Hi @M-Birk,

could you please share the build-wrapper-dump.json file and the entire analysis output log? If you prefer to share it privately I can send you a private message where you can share.

Hi @mpaladin,
i would be more comfortable sharing it privately

Hi @M-Birk,

sure, no problem, I sent you a PM.

Hi @M-Birk,

it seems like that you are using qcc compiler, I am sorry to inform you that we currently don’t support qcc compiler, this is the ticket related to it: CPP-2275.