Skip to content
Advertisement

SonarQube Major Issue: Duplicated blocks of code must be removed same class with different annotations

Sonarqube block my build due to Duplicated blocks for this two classes :

@Entity
@Table(name = "my_table")
public class Employee {

  @Id
  @Column(name = "ID")
   Integer  id;
   
   @Column(name = "NAME")
   String name;
   
   @Column(name = "AGE")
   Integer age;

   public void setName(String name) {
      this.name = name;
   }
   public String getName() {
      return name;
   } 
   public void setAge(int age) {
      this.age= age;
   }
   public int getAge() {
      return age;
   }
   
   public void setId(int id) {
      this.id= id;
   }
   
   public int getId() {
      return id;
   }

}

@ApiModel(value = "Employee")
public class EmployeeDTO {

   @ApiModelProperty(required = false, example = "1")
   Integer  id;
   
   @ApiModelProperty(required = false, example = "Jhon")
   String name;
   
   @ApiModelProperty(required = false, example = "25")
   Integer age;

   public void setName(String name) {
      this.name = name;
   }
   public String getName() {
      return name;
   } 
   public void setAge(int age) {
      this.age= age;
   }
   public int getAge() {
      return age;
   }
   
   public void setId(int id) {
      this.id= id;
   }
   
   public int getId() {
      return id;
   }

}

any idea how i can resolve this issue since i don’t want to create an abstract class then inherit from it because i will lose the swagger and JPA annotations and i want to keep the visibility for each class and layer.

thanks.

Advertisement

Answer

Unfortunately, the only real resolution is to set a duplications exclusion for those two classes (assuming this is 1 class/file).

Go to Project Settings -> General Settings -> Analysis Scope -> C. Duplication Exclusions

Advertisement