Sonarqube scan error with line out of range?
Asked Answered
T

13

34

[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.

Tollbooth answered 28/9, 2016 at 16:34 Comment(5)
Which version of SonarQube and of Java Plugin are you using ? what is the encoding of File.java on which this is failing ?Tifanytiff
Hello, Having the same issue with SonarQube 5.6.2, java plugin 4.2, file encoded in utf-8Preachment
It seemed to just start working the day after I posted this.... No changes madeTollbooth
Having the same issue here. Using Maven on a groovy project with SonarQube 6.1.Glamorous
I had the same issue and I resolved it by copy & pasting the entire contents of the offending class into TextWrangler, then copy & pasting it back into Visual Studio. It sounds silly, but I switch back & forth between developing on PC and Mac and I guess I normalized the line breaks at some point, which may have caused an issue.Alum
P
29

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.

Proulx answered 9/1, 2017 at 16:50 Comment(1)
True. I got the same problem and the cause was also an outdated jacoco report.Pistachio
G
5

I tried gradle clean buildand it worked for me

Grapery answered 27/6, 2018 at 5:19 Comment(2)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewStore
@PankajMakwana Disagree. Just because it is short it does not mean it is not an answer. I see this as answer and not a comment.Nessy
F
4

Same damn issue happens in python code as well. I got it resolved adding a blank line at the end of the file.

Folly answered 27/4, 2017 at 21:26 Comment(1)
For me it was the coverage xml that wasn't refreshing with deleted files.Aubree
U
3

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

Unifoliolate answered 20/7, 2017 at 8:26 Comment(0)
D
2

For Azure DevOps, you might want to make sure your build cleans sources before it starts building.

enter image description here

Desalvo answered 21/1, 2022 at 9:44 Comment(0)
M
1

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.

Mindy answered 9/2, 2021 at 11:55 Comment(0)
M
1

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. 😀

Meghannmegiddo answered 15/2 at 14:4 Comment(0)
G
0

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.

Gerome answered 20/5, 2019 at 16:41 Comment(0)
S
0

In my case, an iOS project written in Swift had to remove previous reports. Just delete sonar-reports folder.

Superannuation answered 9/10, 2019 at 10:44 Comment(0)
H
0

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.

Heeling answered 3/11, 2020 at 8:46 Comment(1)
How do you do this? I have this issue as part of an Azure DevOps pipeline.Steinway
M
0

Major reasons for this problem:-

  1. Yes this issue arises when there is a recent change in the repository but you are not using the updated image in the yaml file and this error will always be seen in the latest committed file in the repo.

for ex - docker run -dt --name ${{variables.containerName}} ${{variables.tempimage}} /bin/bash

  1. 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.

  2. 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.

Marion answered 1/7, 2021 at 4:43 Comment(0)
P
0

Delete the coverage reports from the previous run before running again.

Physiognomy answered 26/9, 2022 at 23:22 Comment(0)
L
0

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.

Lynnette answered 23/12, 2023 at 19:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.