False-positive unused assignment while using Lombok @NoArgsConstructor annotation. Lombok generates no-args constructor, so assignment is valid. Such code is usually encountered with JPA entities, where entity can have Lombok generated no-args and explicit copy-constructor constructors.
Code Sample demonstrating the issue:
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class TestClass {
private Long version = 0L;
public TestClass(final TestClass anesthesiaRequestVersion) {
this.version = anesthesiaRequestVersion.version + 1;
}
}
Expected outcome: No PMD violation detected.
PMD reports a violation at line private Long version = 0L;, but that's wrong. That's a false positive.
Affects PMD Version: 6.42.0
Rule: UnusedAssignment
Please provide the rule name and a link to the rule documentation: https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#unusedassignment
Description:
False-positive unused assignment while using Lombok
@NoArgsConstructor
annotation. Lombok generates no-args constructor, so assignment is valid. Such code is usually encountered with JPA entities, where entity can have Lombok generated no-args and explicit copy-constructor constructors.Code Sample demonstrating the issue:
Expected outcome: No PMD violation detected.
PMD reports a violation at line
private Long version = 0L;
, but that's wrong. That's a false positive.Running PMD through: Gradle