Reputation: 1377
[07:43:57]W: [Step 1/1] ERROR: Error during SonarQube Scanner execution
[07:43:57]W: [Step 1/1] ERROR: Line 523 is out of range in the file src/main/java/com/company/package/File.java (lines: 522)
For some reason Sonarqube is reporting an error on line 523 but there is only 522 lines in the source file ?
I saw this on a previous file, but when I added a blank line to the end of it the problem went away, this file already has a blank line at the end of it.
Upvotes: 35
Views: 27511
Reputation: 675
I encountered the same issue in my Python code as well. In my case, updating the coverage version fixed the problem.
Upvotes: 0
Reputation: 1772
I encountered the same problem, and after researching a lot, I found out that the Tests were not being built (so they are not reflecting the latest source code).
1st fix: when calling msbuild.exe I was just using msbuild.exe /t:Rebuild
, now I'm using msbuild.exe /t:Clean;Rebuild
so I can see that no tests were being built anymore.
2nd fix: I was ignoring the errors from TypeScript. So by running msbuild.exe
isolated, I was able to see that TypeScript errors were breaking the msbuild
execution before the tests can be built. Tip: don't ignore any errors and try to run the commands outside the script.
ā This way a fresh test DLL will be built, and when coverage compares the methods/classes it will match the right source code file. š
Upvotes: 1
Reputation: 1
To avoid issues with the coverage report, make sure to delete it before executing it again. First, build your xml file and then execute sonar-scanner. To do this, run the following commands in sequence: coverage xml, coverage html, and sonar-scanner. Alternatively, you can try removing the .coverage and .scannerwork files.
Upvotes: 0
Reputation: 1019
Delete the coverage reports from the previous run before running again.
Upvotes: 1
Reputation: 5065
For Azure DevOps, you might want to make sure your build cleans sources before it starts building.
Upvotes: 2
Reputation: 324
Major reasons for this problem:-
for ex - docker run -dt --name ${{variables.containerName}} ${{variables.tempimage}} /bin/bash
In the above command we are invoking the containerName and then using some tempimage so if this tempimage is updated(means pointing to the latest repo) then only you will be able to resolve this issue if we have a mismatch in the repo at sonarqube and in the yaml file then we will get this issue.
To get the latest image we can use Team_image_builder inside the yaml file and if we remove the latest committed file from the repo then this issue will not come because difference of both sides would be zero then.
Upvotes: 0
Reputation: 5345
We had the same problem on our AspNET-Core-Project.
We then saw, that we had testfailures that unfortunately didn't cause our Jenkins-Job to fail. Instead sonarqube analyzing the tests and coverage produced the error.
Once the tests were fixed everything worked well again.
Upvotes: 1
Reputation: 286
I got the very same error with Azure DevOps Pipelines, but a cleanup before building the solution for sources and output
did the job.
Now everything is working fine again.
Upvotes: 0
Reputation: 1628
In my case, an iOS project written in Swift had to remove previous reports. Just delete sonar-reports folder.
Upvotes: 0
Reputation: 11655
If executing a maven clean does not work check if you have any old project folder that needs to be cleaned. Once you remove a submodule from the maven pom it won't remove the folder including the /target directory with the jacoco report from ages ago.
Upvotes: 0
Reputation: 2079
For me it was because I had exactly the same class (for example com.test.MyClass
) name and package name in two different sub modules (maven), MyClass
in first module is larger i.e. 120 lines of code. MyClass
in second module is shorter, then the exception was thrown since JaCoCo though the report was for that.
Solution was to rename one of the classes or move it into a different package.
i.e. :
com.test.MyClass
and
com.test.MyClassB
OR:
com.test.MyClass
and
com.test.foo.MyClass
Upvotes: 3
Reputation: 1057
Same damn issue happens in python code as well. I got it resolved adding a blank line at the end of the file.
Upvotes: 4
Reputation: 1144
I had the same issue when using sonar maven plugin and jacoco test reports. mvn sonar:sonar
relies on an existintig jacoco report, when the source code was changed (lines had been removed), but the test report wasn't updated this error occurred. Running mvn clean test sonar:sonar
solved it.
Upvotes: 29