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