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: false positive with TestNG annotations #4268

Closed
LynnBroe opened this issue Dec 21, 2022 · 1 comment · Fixed by #4536
Closed

[java] CommentDefaultAccessModifier: false positive with TestNG annotations #4268

LynnBroe opened this issue Dec 21, 2022 · 1 comment · Fixed by #4536
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@LynnBroe
Copy link
Contributor

LynnBroe commented Dec 21, 2022

Affects PMD Version:6.50.0

Rule: CommentDefaultAccessModifier

Description:
In the rule CommentDefaultAccessModifier, I found PMD can raise a wanring for org.testng.annotations.Test, but when I used org.junit.jupiter.api.Test, it does not report the warning, hence I think this is a false positive because these two annotations are equal and the behavior should be consistent.

Code Sample demonstrating the issue:

import org.testng.annotations.Test;
public class C {
    @Test
    void foo() {
        synchronized (this) {}
    }
}

Expected outcome:

PMD should not report a violation at line 3. This is a false positive.

Running PMD through: [Maven]

@LynnBroe LynnBroe added the a:false-positive PMD flags a piece of code that is not problematic label Dec 21, 2022
@adangel adangel changed the title [java] False positive about the rule CommentDefaultAccessModifier [java] CommentDefaultAccessModifier - false positive with TestNG's @Test annotation Jan 19, 2023
@adangel adangel changed the title [java] CommentDefaultAccessModifier - false positive with TestNG's @Test annotation [java] CommentDefaultAccessModifier: false positive with TestNG's @Test annotation May 19, 2023
@adangel
Copy link
Member

adangel commented May 19, 2023

these two annotations are equal and the behavior should be consistent

Only if the two test frameworks behave the same. In the official TestNG documentation, all examples use public methods. But it seems, that default access also works with TestNG.

Please also note, that if @Test is used as a class annotation, only public methods will be considered: https://testng.org/doc/documentation-main.html#class-level

The effect of a class level @Test annotation is to make all the public methods of this class to become test methods even if they are not annotated.

@adangel adangel changed the title [java] CommentDefaultAccessModifier: false positive with TestNG's @Test annotation [java] CommentDefaultAccessModifier: false positive with TestNG annotations May 19, 2023
@adangel adangel added this to the 7.0.0 milestone May 19, 2023
adangel added a commit to adangel/pmd that referenced this issue May 19, 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
2 participants