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
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
@NoArgsConstructorgenerates a public constructorpublic C()but PMD considers theCclass only has private constructor and does not have any static methods or fields cannot be used which triggersMissingStaticMethodInNonInstantiatableClassLombok Documentation: https://projectlombok.org/features/constructor
Note: there are more annotations, like
@RequiredArgsConstructorand@AllArgsConstructor.Code Sample demonstrating the issue:
Original code:
Changed:
Expected outcome:
PMD reports a violation at line 4, but that's wrong. That's a false positive.
Running PMD through: CLI