-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[java] Fix #6096: Detect Lombok generated equals/hashCode in Comparable #6238
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
Conversation
Detect generated equals and hashCode in Comparable when neither method has been implemented manually.
|
Compared to main: (comment created at 2025-11-20 21:01:40+00:00 for 8ab254e) |
|
Not sure about the line break in the Set init line. What is the preferred max line length for the project? |
adangel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
This will solve it for that rule.
optional request:
For Lombok, we actually have a bit more in mind (see #3119):
- in we could actually add fake methods for the generated equals and hashCode methods
pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/ast/AstClassSym.java
Line 158 in 33f00ec
public void processLombok(JavaAstProcessor processor) { - in the rule wouldn't iterate over the ast, but over the symbols (using
Line 35 in 33f00ec
for (ASTMethodDeclaration m : node.getDeclarations(ASTMethodDeclaration.class)) { node.getSymbol().getDeclaredMethods()) and would see then the generated methods as well
If you like, you can give it a try, maybe in a separate PR.
...sourceforge/pmd/lang/java/rule/errorprone/OverrideBothEqualsAndHashCodeOnComparableRule.java
Outdated
Show resolved
Hide resolved
...sourceforge/pmd/lang/java/rule/errorprone/OverrideBothEqualsAndHashCodeOnComparableRule.java
Outdated
Show resolved
Hide resolved
.../sourceforge/pmd/lang/java/rule/errorprone/xml/OverrideBothEqualsAndHashCodeOnComparable.xml
Outdated
Show resolved
Hide resolved
.../sourceforge/pmd/lang/java/rule/errorprone/xml/OverrideBothEqualsAndHashCodeOnComparable.xml
Outdated
Show resolved
Hide resolved
around 120 I think |
adangel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Describe the PR
Rule: OverrideBothEqualsAndHashCodeOnComparable
Detect generated equals and hashCode in Comparable when neither method has been implemented manually.
Currently Lombok
@EqualsAndHashCode,@Dataand@Valueare detected.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)