Affects PMD Version:7.0.0-rc1
Rule: OverrideBothEqualsAndHashcode
Please provide the rule name and a link to the rule documentation:
https://docs.pmd-code.org/latest/pmd_rules_java_errorprone.html#overridebothequalsandhashcode
Description:
The anonymous class inside class B only has an equal
method without hashCode
method. It should be reported like the class A. I think this is a false negative. PMD mistakenly thinks hashCode
method in B belong to the inner anonymous class.
Code Sample demonstrating the issue:
public class Foo { public class A { Object o = new Object() { public boolean equals(Object other) { // report a warning return false; } }; } public class B { Object o = new Object() { public boolean equals(Object other) { // report no warning return false; } }; public int hashCode() { return 1; } } }
The test example is found when using @EqualsAndHashCode from Lombok.
Expected outcome:
PMD reports no violations at line 11, but that's wrong. That's a false negative.
Running PMD through: CLI
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4