How do I suppress CheckStyle StrictDuplicate warning?

1.1k views Asked by At

I am trying to suppress CheckStyle StrictDuplicateCode warning, and it does not work. In my Eclipse project, I have two classes with similar fields:

public class MyClass {
    // CHECKSTYLE:OFF
    private String field1;

    private String field2;

    private String field3;

    private String field4;

    private String field5;

    private String field6;

    private String field7;

    private String field8;
}

public class MyDuplicateClass {
    // CHECKSTYLE:OFF
    private String field1;

    private String field2;

    private String field3;

    private String field4;

    private String field5;

    private String field6;

    private String field7;

    private String field8;
}

Putting "CHECKSTYLE:OFF" comment in one or both classes does not suppress the warning. Am I missing something?

1

There are 1 answers

1
michael667 On

Make sure you configured the SuppressionCommentFilter correctly, for example:

<module name="Checker">

  <module name="SuppressionCommentFilter">
    <property name="offCommentFormat" value="CHECKSTYLE\:OFF ([\w\|]+)"/>
    <property name="onCommentFormat" value="CHECKSTYLE\:ON ([\w\|]+)"/>
    <property name="checkFormat" value="$1"/>
  </module>

  <module name="TreeWalker">

...