Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#687 SuppressionCommentFilter does not suppress StrictDuplicateCode Warnings

release_5.0
closed
nobody
None
1
2013-10-26
2012-10-31
Christoph Böhme
No

The SuppressionCommentFilter does not suppress warnings generated by the StrictDuplicateCode module.

My checkstyle configuration is:

<module name="Checker">
  <module name="TreeWalker">
        <module name="FileContentsHolder"/>
        <module name="AvoidInlineConditionals"/>
  </module>
  <module name="StrictDuplicateCode">
    <property name="min" value="5"/>
  </module>
  <module name="SuppressionCommentFilter"/>
</module>

The AvoidInlineConditionals is only included to verify that suppression is configured correctly.

In the java file checkstyle is disabled using comments:

public class StrictDuplicateCodeTest {

        // CHECKSTYLE:OFF

        public static void main(String[] args) {
                int i = 1;
                i += i == 1 ? 2 : 3;
                /* Some random comments
                 * in order to
                 * produce some
                 * duplicate
                 * code.
                 */
                duplicatedCode(i);
        }

        public static int duplicatedCode(int j) {
                int i = 1;
                i += i == 1 ? 2 : 3;
                /* Some random comments
                 * in order to
                 * produce some
                 * duplicate
                 * code.
                 */
                i += j;
                return i;
        }

        // CHECKSTYLE:ON
}

In my understanding checkstyle should not produce any warnings when checking this file. However, when running checkstyle on the file I get the following output:

java -jar checkstyle-5.6/checkstyle-5.6-all.jar -c checkstyle.xml StrictDuplicateCodeTest.java
Starting audit...
StrictDuplicateCodeTest.java:6: 8 gleiche Zeilen in StrictDuplicateCodeTest.java, beginnend bei Zeile 18
Audit done.

If I remove the two CHECKSTYLE comments from the file then the output also includes two AvoidInlineConditional warnings:

java -jar checkstyle-5.6/checkstyle-5.6-all.jar -c checkstyle.xml StrictDuplicateCodeTest.java
Starting audit...
D:\\StrictDuplicateCodeTest.java:5:29: Der Bedingungsoperator sollte vermieden werden.
D:\\StrictDuplicateCodeTest.java:17:29: Der Bedingungsoperator sollte vermieden werden.
StrictDuplicateCodeTest.java:4: 8 gleiche Zeilen in StrictDuplicateCodeTest.java, beginnend bei Zeile 16
Audit done.

Discussion

  • Roman Ivanov
    Roman Ivanov
    2013-10-26

    • status: open --> closed