VisualStudioCoverageSensor line is out of range

We have a similar issue with sonar.cfamily.vscoveragexml.reportsPath. I tested it with sonar-cfamily-plugin- at SonarQube Enterprise Edition version 8.1 (build 31237) without success.

java.lang.IllegalStateException: Line 190 is out of range in the file <PROJECT>/<SOURCE_FILE>.cpp (lines: 189)
	at org.sonar.api.utils.Preconditions.checkState(
	at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(
	at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.lineHits(
	at com.sonar.cpp.plugin.visualstudio.VisualStudioCoverageSensor.execute(
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(
	at org.sonar.core.platform.ComponentContainer.startComponents(
	at org.sonar.core.platform.ComponentContainer.execute(
	at org.sonar.scanner.scan.ProjectScanContainer.scan(
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(
	at org.sonar.core.platform.ComponentContainer.startComponents(
	at org.sonar.core.platform.ComponentContainer.execute(
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(
	at org.sonar.core.platform.ComponentContainer.startComponents(
	at org.sonar.core.platform.ComponentContainer.execute(
	at org.sonar.batch.bootstrapper.Batch.doExecute(
	at org.sonar.batch.bootstrapper.Batch.execute(
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.base/java.lang.reflect.Method.invoke(
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(
	at org.sonarsource.scanner.cli.Main.execute(
	at org.sonarsource.scanner.cli.Main.execute(
	at org.sonarsource.scanner.cli.Main.main(

Hi @HofmeisterAn,

would you be able to share the entire sonar-scanner output log and the visual studio coverage report?
I can send you a PM where you can share privately.

@mpaladin Of course, a PM would be nice - thanks. I noticed that the file only has 189 lines instead of 190. I have this issue with a couple of files. Sonar always complains about a length +1.

For the records it seems that the generated xml report was containing invalid lines and so the sensor was failing because of invalid lines.

Everything seems to be good on the analyzer side, the issue comes from the report generation which is not under our control, we can consider this topic as closed.

I ran into this same issue. Looking into the coverage XML file I was able to see that a function was being added by the pre-compiler (__empty_global_delete) at the end of the source file. I just had to add an exclusion filter to my test settings and problem solved.

Hi @Sean_Jost,

thank you for your information, would you be able to provide a small reproducer to show what happens?

@Sean_Jost Can you explain how you fixed your issue? We still face it. At some places we noticed that removing C++ 14 language features “fix” it, but that’s only a workaround. We also notice that it behaves different with certain runsettings. Did you change your runsetting like DynamicCoverageDataCollector?

Hi @HofmeisterAn,

if it happens only on test files you may want to just exclude them from the analysis.

I am not sure to whom you are addressing this question.

Hi @mpaladin,

It happens on our source files, a lot of them. Until now, we’re not able to analyze C++ projects at all. At least with code coverage enabled. Which is disappointing.

This was addressed to @Sean_Jost. Maybe he can explain a little bit more what he excluded.

I attached our findings below. Maybe they will help one or the other:

  1. We noticed that each broken source file contains a function that is covered by two source files (.h; .cpp). All other functions are covered by a single file.

  2. We noticed different behaviors as soon as we exclude <Source>.*\\vc\\tools\\msvc\\.*</Source>, a bunch of errors are gone, but still too many left. Notice that in previous versions of Visual Studio those files were excluded by <Source>.*\\vctools\\.*</Source> which is the default configuration by Microsoft. In the latest versions of Visual Studio, Microsoft moved them to vc\tools\msvc\.

  3. Even only including our own namespace in the code coverage analysis won’t work. We still get the line is out of range exception.

  4. Removing C++ 14 language features fixed some issues.

  5. <SupportJustMyCode>false</SupportJustMyCode> fixed some issues, see 411331@Developer Community.

Hi @HofmeisterAn,

thank you for the link, I am going to give a look, it may help to understand a bit better the situation. If you provide us a minimal project reproducing the issue it would be easier for us. Given the situation we may evaluate to ignore reports related to unexisting line numbers.

Hi @HofmeisterAn,

I created a ticket to track the issue: CPP-2879. We are going to ignore entries on exceeding line numbers, it is going to be released in the next version.

Hi @mpaladin,

thanks a lot. We will test the fix as soon as it is available. I’ll get in touch with you afterwards. If we still have any issues, I’ll try to get a sample project from my colleges.


1 Like

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