Sonarqube scan error with line out of range?

2020-02-26 04:51发布

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

6条回答
Viruses.
2楼-- · 2020-02-26 05:22

I tried gradle clean buildand it worked for me

查看更多
Deceive 欺骗
3楼-- · 2020-02-26 05:27

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.

查看更多
Fickle 薄情
4楼-- · 2020-02-26 05:27

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

查看更多
你好瞎i
5楼-- · 2020-02-26 05:29

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

查看更多
爷、活的狠高调
6楼-- · 2020-02-26 05:31

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

查看更多
干净又极端
7楼-- · 2020-02-26 05:38

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.

查看更多
登录 后发表回答