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] MissingStaticMethodInNonInstantiatableClass should consider Lombok's @NoArgsConstructor #4225

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

Comments

@ghost
Copy link

ghost commented Nov 22, 2022

Affects PMD Version:6.51.0

Rule: MissingStaticMethodInNonInstantiatableClass

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass

Description:
In the following code example, the @NoArgsConstructor generates a public constructor public C() but PMD considers the C class only has private constructor and does not have any static methods or fields cannot be used which triggers MissingStaticMethodInNonInstantiatableClass

Lombok Documentation: https://projectlombok.org/features/constructor

Note: there are more annotations, like @RequiredArgsConstructor and @AllArgsConstructor.

Code Sample demonstrating the issue:

Original code:

import lombok.NoArgsConstructor;

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

Changed:

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

    public C() {
    }
}

Expected outcome:

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

Running PMD through: CLI

@ghost ghost added the a:false-positive PMD flags a piece of code that is not problematic label Nov 22, 2022
@adangel adangel changed the title [java] MissingStaticMethodInNonInstantiatableClass should considers lombok's @NoArgsConstructor [java] MissingStaticMethodInNonInstantiatableClass should consider Lombok's @NoArgsConstructor Nov 22, 2022
@adangel adangel added this to the 6.53.0 milestone Nov 22, 2022
@adangel adangel modified the milestones: 6.53.0, 6.52.0 Nov 25, 2022
adangel added a commit to adangel/pmd that referenced this issue Nov 25, 2022
adangel added a commit to adangel/pmd that referenced this issue Nov 25, 2022
[java] Fix pmd#4225 MissingStaticMethodInNonInstantiatableClass: Exclude lombok's @NoArgsConstructor annotation pmd#4227
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
1 participant