Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube: Can't create measure for line X for file with file with <X lines

We recently upgraded our SonarQube server to the latest version (5.3) as well as upgrading all the plugins. The server only monitors a single build at the moment, of a C# project built by Visual Studio Team Services (was Visual Studio Online).

At first, all worked well (apart from a long standing issue I'll describe in another question). But after a while we started getting errors like the one below when trying to push data to SQ:

ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
    at org.sonar.runner.api.Runner.execute(Runner.java:100)
    at org.sonar.runner.Main.executeTask(Main.java:70)
    at org.sonar.runner.Main.execute(Main.java:59)
    at org.sonar.runner.Main.main(Main.java:53)
Caused by: java.lang.IllegalStateException: Can't create measure for line 47 for file '[PATH]/[FILENAME].cs' with 45 lines
    at org.sonar.batch.sensor.coverage.CoverageExclusions.validateMaxLine(CoverageExclusions.java:158)
    at org.sonar.batch.sensor.coverage.CoverageExclusions.validate(CoverageExclusions.java:129)
    at org.sonar.batch.deprecated.DeprecatedSensorContext.saveMeasure(DeprecatedSensorContext.java:204)
    at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.analyze(CoverageReportImportSensor.java:78)
    at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.analyse(CoverageReportImportSensor.java:59)
    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50)
    at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:98)
    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:185)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:243)
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:238)
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236)
    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:228)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
    at org.sonar.batch.task.ScanTask.execute(ScanTask.java:55)
    at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
    at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:122)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:79)
    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
    ... 9 more

We found a post (https://groups.google.com/forum/#!topic/sonarqube/Xju6ichZe_k) which describes a solution involving changing the code of one of the plugins (sonar-dotnet-tests-library) and replacing the built file on the server. Being .NET-heads, we wouldn't mind not having to modifying other peoples Java libraries to get this to work ;)

Is this the solution to the problem, or is there anything else which might be causing this? At the moment it stops us form pushing data to SonarQube, which is a shame...

like image 806
Christian Rygg Avatar asked Feb 26 '16 12:02

Christian Rygg


2 Answers

There seems to be a problem in the Code Coverage tooling that ships with Visual Studio 2015. The problem should be fixed with Visual Studio 2015 Update 3.

The hosted agent should be updated with Update 3 soon after it is released as well, the TFS build team are quite fast on that. For a list of software available on the hosted agent see here.

Workarounds until then:

  1. don't generate a code coverage file, for example by disabling the option in the VS Test build task
  2. some users reported the problem does not occur with VS 2013, so you might want to build and/or test with it instead of using VS 2015
like image 138
Bogdan Gavril MSFT Avatar answered Oct 20 '22 00:10

Bogdan Gavril MSFT


For me this turned out to be because OpenCover reports from previous builds were being left behind on Jenkins.

Once I ensured that they were all removed the problem went away, I presuming having multiple reports meant it was trying to process files more than once.

like image 45
user3617723 Avatar answered Oct 20 '22 00:10

user3617723