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 should consider lombok's @Value #4200

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

Comments

@LynnBroe
Copy link
Contributor

LynnBroe commented Nov 9, 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:
In the following code example, @Value can add a final modifier to the class Test and causes a false positive that PMD considers it is a class with only private constructors but no final modifier.

Code Sample demonstrating the issue:

import lombok.Value;

@Value
public class Test {
    private Test(int a, int b, int c, String abc, long d, double p, String[] arr, int data, long in, float fl, String res) {}
}

Expected outcome:

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

Running PMD through: CLI

@LynnBroe LynnBroe added the a:false-positive PMD flags a piece of code that is not problematic label Nov 9, 2022
LynnBroe added a commit to LynnBroe/pmd that referenced this issue Nov 9, 2022
LynnBroe added a commit to LynnBroe/pmd that referenced this issue Nov 10, 2022
LynnBroe added a commit to LynnBroe/pmd that referenced this issue Nov 10, 2022
@adangel adangel changed the title ClassWithOnlyPrivateConstructorsShouldBeFinal should consider lombok's @Value [java] ClassWithOnlyPrivateConstructorsShouldBeFinal should consider lombok's @Value Nov 10, 2022
@adangel adangel added this to the 6.52.0 milestone Nov 11, 2022
adangel added a commit to adangel/pmd that referenced this issue Nov 11, 2022
[java] Fix pmd#4200 and pmd#4201: ClassWithOnlyPrivateConstructorsShouldBeFinal, CommentDefaultAccessModifier: Exclude lombok @value annotation pmd#4202
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