Skip to content

FileContents.getJavadocBefore(): Comments should not be skipped if it is not alone in line #16641

@mahfouz72

Description

@mahfouz72

#16546 (comment)

Detected at the report:
https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/f4d37cb_2025053704/reports/diff/index.html

unfortunately, In my previous PR the config in the PR description was missing some important checks, so the report generated shows no difference but this was misleading.

After I checked a report in another PR (that was behind my commit on master). I saw the real diff due to my changes and analyzed the report all was good except for this case and the like

Example:

D:\CS\test
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="JavadocVariable"/>
    </module>
</module>

D:\CS\test
cat src/Test.java
class Test {
    /**
     *  Javadoc
     */
    /* package */ int x;

    int y;
}
D:\CS\test
java  -jar checkstyle-10.22.0-SNAPSHOT-all.jar -c config.xml src/Test.java
Starting audit...
Audit done.

The issue because we skipped the line /* package */ int x; because it has a block comment. so int y becomes associated with the Javadoc above int x.

The fix should be simple. A simple condition to see if the block comment is in a single line and not alone in the line
then we should not skip it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions