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

[java] CommentDefaultAccessModifier comment needs to be before annotation if present #4578

Closed
harbulot opened this issue May 26, 2023 · 0 comments · Fixed by #4591
Closed
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@harbulot
Copy link

Affects PMD Version: 7.0.0-rc2

Rule: CommentDefaultAccessModifier

Description:

Code Sample demonstrating the issue:

    @SuppressWarnings("")
    /* package */ void test1() {
        System.out.println("This triggers CommentDefaultAccessModifier");
    }

    /* package */ @SuppressWarnings("")
    void test2() {
        System.out.println("This does not trigger CommentDefaultAccessModifier");
    }

Expected outcome:

(I'm not sure if this is intended, and it's probably a matter of opinion.)

  • In test1 above, where the comment meant to represent a package modifier is after the annotation on that method, a CommentDefaultAccessModifier rule violation is flagged up.
  • This is not the case in test2, where that comment is before the annotation.

Since /* package */ seems to be intended to replace a public/private/protected modifier that doesn't exist for default access, it feels it would fit more naturally where those modifiers would be, i.e. between the annotations and the return type (as in test1).
However, this is currently flagged as a CommentDefaultAccessModifier rule violation.

Running PMD through: Maven (using maven-pmd-plugin version 3.20.1-pmd-7-SNAPSHOT configured with PMD 7.0.0-rc2)

@harbulot harbulot added the a:false-positive PMD flags a piece of code that is not problematic label May 26, 2023
jsotuyod added a commit to Monits/pmd that referenced this issue Jun 6, 2023
jsotuyod added a commit to Monits/pmd that referenced this issue Jun 6, 2023
@jsotuyod jsotuyod added the has:pr label Jun 6, 2023
@adangel adangel added this to the 7.0.0 milestone Oct 6, 2023
@adangel adangel closed this as completed in e31c77c Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
3 participants