Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonarqube scan error with line out of range?

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

like image 771
Ro. Avatar asked Sep 28 '16 16:09

Ro.


People also ask

Do SonarQube and SonarQube scanners need to be in the same network?

SonarQube Scanners don't need to be on the same network as the SonarQube Server. There is no communication between SonarQube Scanners and the SonarQube Database.


5 Answers

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.

like image 164
Don Avatar answered Oct 10 '22 01:10

Don


I tried gradle clean buildand it worked for me

like image 34
StackUser Avatar answered Oct 10 '22 03:10

StackUser


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

like image 24
MFIhsan Avatar answered Oct 10 '22 01:10

MFIhsan


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

like image 33
Hamid Avatar answered Oct 10 '22 03:10

Hamid


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.

like image 1
AlexS Avatar answered Oct 10 '22 01:10

AlexS