Skip to content

JavadocStyle doesn't work with inline @return #12600

@Juuxel

Description

@Juuxel

I have read check documentation: https://checkstyle.org/config_javadoc.html#JavadocStyle
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

C:\Users\Juuz>javac Test.java

C:\Users\Juuz>type checkstyle.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="JavadocStyle"/>
    </module>
</module>

C:\Users\Juuz>type Test.java
class Test {
    /**
     * {@return a string}
     */
    String foo() {
        return "Hello, world";
    }
}

C:\Users\Juuz>set RUN_LOCALE="-Duser.language=en -Duser.country=US"

C:\Users\Juuz>java %RUN_LOCALE% -jar Downloads\checkstyle-10.6.0-all.jar -c checkstyle.xml Test.java
Starting audit...
[ERROR] C:\Users\Juuz\Test.java:2: First sentence should end with a period. [JavadocStyle]
Audit done.
Checkstyle ends with 1 errors.

JavadocStyle requires a period after the first sentence, but it doesn't consider inline {@return} tags which insert a period after the contents.

For the example file with {@return a string}, this is what javadoc -package Test.java (JDK 19) generates:

method summary
method javadoc

This seems to be related to #10776, which is a similar issue with a different check.

Note: A workaround is to add a . after the {@return} tag.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions