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] FieldNamingConventions: false positive with lombok's @UtilityClass #4455

Closed
LynnBroe opened this issue Apr 6, 2023 · 0 comments · Fixed by #4537
Closed

[java] FieldNamingConventions: false positive with lombok's @UtilityClass #4455

LynnBroe opened this issue Apr 6, 2023 · 0 comments · Fixed by #4537
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@LynnBroe
Copy link
Contributor

LynnBroe commented Apr 6, 2023

Affects PMD Version:7.0.0-rc1

Rule: FieldNamingConventions

Please provide the rule name and a link to the rule documentation:
https://docs.pmd-code.org/latest/pmd_rules_java_codestyle.html#fieldnamingconventions

Description:
The Test1 uses @UtilityClass, making the field static. So the two classes Test1 and Test2 are equivalent. However, PMD reports a warning in Test1 and no warnings in Test2 because PMD does not consider the annotation @UtilityClass. PMD should not report a warning in Test1 like the Test2.

Code Sample demonstrating the issue:

import lombok.experimental.UtilityClass;
public  class Foo {
    @UtilityClass
    public class Test1 {
        private final String FINAL_F = "final_field";  // report a warning
    }
    public class Test2 {
        private static final String FINAL_F = "final_field";  // report no warning
    }
}

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 Apr 6, 2023
@LynnBroe LynnBroe changed the title false-positive about FieldNamingConventions and UtilityClass [java]A false-positive about FieldNamingConventions and UtilityClass Apr 24, 2023
@LynnBroe LynnBroe changed the title [java]A false-positive about FieldNamingConventions and UtilityClass [java]A false positive about FieldNamingConventions and UtilityClass Apr 24, 2023
@adangel adangel changed the title [java]A false positive about FieldNamingConventions and UtilityClass [java] FieldNamingConventions: false positive with lombok's UtilityClass May 4, 2023
@adangel adangel changed the title [java] FieldNamingConventions: false positive with lombok's UtilityClass [java] FieldNamingConventions: false positive with lombok's @UtilityClass May 4, 2023
@adangel adangel added this to the 7.0.0 milestone May 28, 2023
adangel added a commit to adangel/pmd that referenced this issue May 28, 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
Development

Successfully merging a pull request may close this issue.

2 participants