Skip to content

False Positive and Negative in SummaryJavaDocCheck #13347

@Kevin222004

Description

@Kevin222004

I have read check documentation: https://checkstyle.org/checks/javadoc/summaryjavadoc.html#SummaryJavadoc
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words


False positive case

kevin@inspiron-15-5510:~/Desktop/check_style$ javac Test.java

kevin@inspiron-15-5510:~/Desktop/check_style$ cat Test.java
public class Test {
    /**
     * {@summary Returns the customer ID.
     *  This method returns. }
     */
    public void foo() {
    }
}

kevin@inspiron-15-5510:~/Desktop/check_style$ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC 
 "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
 "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="SummaryJavadoc">
            <property name="violateExecutionOnNonTightHtml" value="true" />
            <property name="forbiddenSummaryFragments"
                value="^Returns the customer ID. This method returns.$" />
        </module>

    </module>
</module>


kevin@inspiron-15-5510:~/Desktop/check_style$ java -jar /home/kevin/Downloads/checkstyle-10.12.1-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /home/kevin/Desktop/check_style/Test.java:3: Forbidden summary fragment. [SummaryJavadoc]
Audit done.
Checkstyle ends with 1 errors.
kevin@inspiron-15-5510:~/Desktop/check_style$ 

Describe what you expect in detail.
No violation is expected


False Negative case

kevin@inspiron-15-5510:~/Desktop/check_style$ cat Test.java
public class Test {
    /**
     * {@summary Returns the customer ID.
     *  This method returns. }
     */
    public void foo() {
    }
}
kevin@inspiron-15-5510:~/Desktop/check_style$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC 
 "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
 "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="SummaryJavadoc">
            <property name="violateExecutionOnNonTightHtml" value="true" />
            <property name="forbiddenSummaryFragments"
                value="^Returns the customer ID. This method returns. $" />
                            <!-- attention to extra space before $  ^^^ -->
        </module>

    </module>
</module>

kevin@inspiron-15-5510:~/Desktop/check_style$ java -jar /home/kevin/Downloads/checkstyle-10.12.1-all.jar -c config.xml Test.java
Starting audit...
Audit done.
kevin@inspiron-15-5510:~/Desktop/check_style$ 

Expected
expected violation

from #13311 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions