Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false positive invalid tag JavadocType #16087

Open
Machine-Maker opened this issue Dec 29, 2024 · 4 comments
Open

false positive invalid tag JavadocType #16087

Machine-Maker opened this issue Dec 29, 2024 · 4 comments

Comments

@Machine-Maker
Copy link

Machine-Maker commented Dec 29, 2024

https://checkstyle.org/checks/javadoc/javadoctype.html#JavadocType

/var/tmp $ javac Test.java
# success

/var/tmp $ cat checkstyle.xml
<!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="JavadocType"/>
  </module>
</module>

/var/tmp $ cat Test.java
/**
 * <pre>{@code
 * @Internal
 * class Other {
 *   @Nullable String test(String param) {
 *   }
 * }
 * }</pre>
 */
public class Test {
  public void test(String param) {
  }
}

/var/tmp $ java -jar checkstyle-10.21.0-all.jar -c checkstyle.xml test.java
Starting audit...
[ERROR] /Users/jake/Projects/Java/checkstyle-test/Test.java:3:4: Unknown tag 'Internal'. [JavadocType]
[ERROR] /Users/jake/Projects/Java/checkstyle-test/Test.java:5:6: Unknown tag 'Nullable'. [JavadocType]
Audit done.
Checkstyle ends with 2 errors.

@Internal and @Nullable should not be reported as an unknown tag. It is inside a valid pre/code tag combo which is displayed correctly by the javadoc tool. You can see the rendered html below.
CleanShot 2024-12-29 at 07 39 32@2x

@romani
Copy link
Member

romani commented Dec 29, 2024

All logic is at https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTypeCheck.java#L154

It is Check, old Check, that doesn't use AST.
So fixing issue on it might be not easy.

But issue is valid, no violations are expected.

@Machine-Maker
Copy link
Author

Machine-Maker commented Dec 29, 2024

For anyone else who finds this, I kinda solved it with the following suppression filter

    <module name="SuppressionSingleFilter">
        <property name="checks" value="Javadoc(Method|Type)"/>
        <!--[A-Z].* check is for java annotations inside code blocks inside javadocs-->
        <property name="message" value="^Unknown tag '(${custom_javadoc_tags}|[A-Z].*)'.$"/>
    </module>

${custom_javadocs_tags} is an injected property with all the custom javadoc tags registered with the javadoc tool in gradle (in my case, just apiNote). But after that, the [A-Z].* regex, just suppresses warnings if the first letter of the tag is capital (which isn't the case for any real javadoc tag and is the case for most (normal) java annotations).

@XN137
Copy link
Contributor

XN137 commented Jan 7, 2025

hitting a similar issue after upgrading from 10.20.0 to 10.21.1:
#14573 (comment)

it seems like content inside <pre>..</pre> isnt ignored (but should be?).

@romani
Copy link
Member

romani commented Jan 7, 2025

It should be.
Main rule: if javadoc passed/generated by jdk tool javadoc , so checkstyle should support such javadoc also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants