How do I ignore duplicated code report in Sonar?

Neriudon :

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!

Yogen Rai :

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: enter image description here

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=91248&siteId=1