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] ClassWithOnlyPrivateConstructorsShouldBeFinal false positive with Lombok's @NoArgsConstructor #4188

Closed
ghost opened this issue Nov 3, 2022 · 0 comments · Fixed by #4192
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@ghost
Copy link

ghost commented Nov 3, 2022

Affects PMD Version:6.51.0

Rule:ClassWithOnlyPrivateConstructorsShouldBeFinal

Please provide the rule name and a link to the rule documentation:
https://pmd.sourceforge.io/pmd-6.51.0/pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal

Description:
Hi, I found a false positive about this rule, please read the following code example. PMD should not report a warning for this class because @NoArgsConstructor can add a constructor for this class. Hence, I think this is a false positive.

Code Sample demonstrating the issue:

import lombok.NoArgsConstructor;
@NoArgsConstructor
public class C {
    private C(String[] arr, long in, String res) {}
}

Expected outcome:

PMD reports a violation at line 3, but that's wrong. That's a false positive.

Running PMD through: [Maven]

@ghost ghost added the a:false-positive PMD flags a piece of code that is not problematic label Nov 3, 2022
@adangel adangel changed the title [java] A false positive about the rule ClassWithOnlyPrivateConstructorsShouldBeFinal [java] ClassWithOnlyPrivateConstructorsShouldBeFinal false positive with Lombok's @NoArgsConstructor Nov 4, 2022
@adangel adangel added this to the 6.52.0 milestone Nov 4, 2022
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
Development

Successfully merging a pull request may close this issue.

1 participant