Skip to content

[java] CommentRequired doesn't consider annotations and records #4515

@adangel

Description

@adangel

Affects PMD Version: 6.x/7.0.0-rc1

Rule: CommentRequired

Description:

With PMD 7.0.0-rc1, methods inside annotations are now reported. But a missing type-level javadoc for the annotation type is not reported.

Also, missing type-level javadoc for records are not reported.

Found via #3123.

When fixing that, we probably need two additional properties: annotationCommentRequirement and recordCommentRequirement.

Code Sample demonstrating the issue:

@interface MyAnnotation1 { // comment required
    String name(); // comment required
    int version(); // comment required
}

record MyRecord(int a) {} // comment required

Expected outcome:

PMD 7.0.0-rc1 reports only 2 violations at line 2+3. PMD 6.55.0 doesn't report these at all.
PMD should report a violation at line 1+6, but doesn't. This is a false-negative.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions