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.

Community
  • 1
  • 1
Ro.
  • 1,357
  • 4
  • 13
  • 25
  • Which version of SonarQube and of Java Plugin are you using ? what is the encoding of _File.java_ on which this is failing ? – Nicolas B. Sep 29 '16 at 07:00
  • Hello, Having the same issue with SonarQube 5.6.2, java plugin 4.2, file encoded in utf-8 – zageyiff Oct 06 '16 at 20:00
  • It seemed to just start working the day after I posted this.... No changes made – Ro. Oct 07 '16 at 08:15
  • Having the same issue here. Using Maven on a groovy project with SonarQube 6.1. – Deven Phillips Nov 23 '16 at 14:29
  • 1
    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. – iupchris10 Jan 16 '18 at 20:28

11 Answers11

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.

Don
  • 1,134
  • 8
  • 15
5

I tried gradle clean buildand it worked for me

StackUser
  • 123
  • 1
  • 7
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/20135676) – Pankaj Makwana Jun 27 '18 at 07:33
  • 5
    @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. – geisterfurz007 Jun 27 '18 at 07:40
4

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

MFIhsan
  • 1,037
  • 3
  • 15
  • 35
2

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

hamid
  • 2,033
  • 4
  • 22
  • 42
2

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

enter image description here

emp
  • 4,926
  • 2
  • 38
  • 50
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.

AlexS
  • 5,295
  • 3
  • 38
  • 54
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.

borjab
  • 11,149
  • 6
  • 71
  • 98
0

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

Pau Ballada
  • 1,491
  • 14
  • 13
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.

ICantSeeSharp
  • 171
  • 2
  • 13
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.

Shivam Tyagi
  • 306
  • 3
  • 3
0

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

ravi
  • 949
  • 11
  • 22