java 线超出范围的 Sonarqube 扫描错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39753072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:36:28  来源:igfitidea点击:

Sonarqube scan error with line out of range?

javasonarqubesonarqube-scan

提问by Ro.

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

[07:43:57]W:[步骤 1/1] 错误:SonarQube 扫描仪执行期间出错

[07:43:57]W:[步骤 1/1] 错误:文件 src/main/java/com/company/package/File.java 中的第 523 行超出范围(第 522 行)

For some reason Sonarqube is reporting an error on line 523 but there is only 522 lines in the source file ?

出于某种原因,Sonarqube 在第 523 行报告错误,但源文件中只有 522 行?

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.

我在以前的文件中看到了这个,但是当我在它的末尾添加一个空行时,问题就消失了,这个文件的末尾已经有了一个空行。

回答by Don

I had the same issue when using sonar maven plugin and jacoco test reports. mvn sonar:sonarrelies 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:sonarsolved it.

使用声纳 maven 插件和 jacoco 测试报告时,我遇到了同样的问题。mvn sonar:sonar依赖于existintig jacoco 报告,当源代码发生更改(行已被删除),但测试报告未更新时,会发生此错误。跑步mvn clean test sonar:sonar解决了。

回答by StackUser

I tried gradle clean buildand it worked for me

我试过了gradle clean build,它对我有用

回答by Sam

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), MyClassin first module is larger i.e. 120 lines of code. MyClassin second module is shorter, then the exception was thrown since JaCoCo though the report was for that.

对我来说,这是因为我com.test.MyClass在两个不同的子模块(maven)MyClass中有完全相同的类(例如)名称和包名称,第一个模块更大,即 120 行代码。MyClass在第二个模块中更短,然后自 JaCoCo 以来抛出异常,尽管报告是为此。

Solution was to rename one of the classes or move it into a different package.

解决方案是重命名其中一个类或将其移动到不同的包中。

i.e. : com.test.MyClassand com.test.MyClassB

即: com.test.MyClasscom.test.MyClassB

OR:

或者:

com.test.MyClassand com.test.foo.MyClass

com.test.MyClasscom.test.foo.MyClass

回答by MFIhsan

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

同样该死的问题也发生在 python 代码中。我解决了在文件末尾添加一个空行的问题。

回答by borjab

If executing a maven cleandoes 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.

如果执行maven clean不起作用,请检查您是否有任何需要清理的旧项目文件夹。从 maven pom 中删除子模块后,它不会删除包含 /target 目录的文件夹以及很久以前的 jacoco 报告。

回答by pegpeg

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

就我而言,一个用 Swift 编写的 iOS 项目必须删除以前的报告。只需删除声纳报告文件夹。