How do I ignore duplicated code report in Sonar?(如何忽略 Sonar 中的重复代码报告?)
问题描述
SonarQube 向不同的简单 POJO 类报告为重复代码块",如下所示.在这种情况下,A 和 B 是不同的角色.所以,我认为我不应该创建抽象类.
公共类 A{私人字符串 xxx;//省略其他字段.公共 A() {}公共字符串 getXxx() {返回xxx;}公共无效 setXxx(字符串 xxx){this.xxx=xxx;}//省略其他字段的 setter 和 getter}公共类 B{私人字符串 xxx;//省略其他字段.公共 B() {}公共字符串 getXxx() {返回xxx;}公共无效 setXxx(字符串 xxx){this.xxx=xxx;}//省略其他字段的 setter 和 getter}
严重性为主要.所以,我想忽略它.然后,我将@SuppressWarning("common-java:DuplicatedBlocks") 和@SuppressWarning("all") 添加到这两个类中.但也不容忽视.
虽然在
有时 Sonar 报告的情况并不严重,但又取决于项目性质 :)
但是,就像上面评论中提到的@Stephen,如果 xxx
是相同的字段和继承是有意义的,那么你可以有父抽象类来避免报告.
SonarQube reports as "block of duplicated code" to different simple POJO class like below. In this case, A and B are different role. So, I think that I should not create abstract class.
public class A{
private String xxx;
// omitted other fields.
public A() {}
public String getXxx() {
return xxx;
}
public void setXxx(String xxx) {
this.xxx= xxx;
}
// omitted other fields' setter and getter
}
public class B{
private String xxx;
// omitted other fields.
public B() {}
public String getXxx() {
return xxx;
}
public void setXxx(String xxx) {
this.xxx= xxx;
}
// omitted other fields' setter and getter
}
The severity is Major. So, I would like to ignore it. Then, I added @SuppressWarning("common-java:DuplicatedBlocks") and @SuppressWarning("all") to both classes. But it could not be ignored.
Though similar question was raised in JIRA, but it have been not solved. My SonarQube's version is 6.5. Thanks!
Putting this into the answer section to attach a screenshot:
If you are confident enough that those two blocks of code have different roles, then you can change the reported severity level to Minor
or Info
from web-console. For example, see the screenshot below:
Sometimes Sonar reports as severe on things which are not really severe, but again depends on the project nature :)
However, like @Stephen mentioned on a comment above, if xxx
are same field and inheritance makes sense, then you can have parent abstract class to avoid the report.
这篇关于如何忽略 Sonar 中的重复代码报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何忽略 Sonar 中的重复代码报告?


- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01