GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||
GeezerVison is showing github.com — [java] Fix #5837: New Rule: OverrideBothEqualsAndHashCodeOnComparable by Pankraz76 · Pull Request #5856 · pmd/pmd Conversation
|
|
should i do so? @adangel |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
0b9eb17 to
7dd4b0b
Compare
|
fixed impl, add new case, rerun dogfood. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
7dd4b0b to
6e0acde
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and sorry for the late response.
I think, we should not change the existing rule OverrideBothEqualsAndHashcode. Instead, we should create a new rule.
Reasons: While this could be considered a "false negative fix", it clearly is an incompatible change (as you have notived in the dogfood runs). That's why I'd implement this as a new rule, to not break everybody's build when they upgrade PMD. If it is a new rule, end-users can decide, whether to enable the new rule or not (otherwise they won't have a choice). I only mentioned OverrideBothEqualsAndHashcode to point out, it is similar and the new rule rule be part of error prone (and not best practices).
Also: #5770 #5837 proposes a new rule and not a false-negative fix.
Having this as a new rule also allows to explain in detail, what this rule detects and why it is error prone not to override equals if Comparable is implemented - and also explain, when it is ok (e.g. if you know that you don't use any sorted collections).
Then, you can separate the cleanup of PMD's code itself into a separate PR, when we enable this rule in our ruleset.
Also, please fix PR description, as this PR mentions the wrong issue....
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Agree. Also, my assumption was wrong — these could collide, meaning fixing one, then might collide with the other, since they are different, as supposed to. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
2e537d4 to
a2a347f
Compare
There was an error while loading. Please reload this page.
|
item: [INFO] blocked by: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
its done but blocked by the checkstyle annoyance foo. If you consider this contribution fix the import, as im not going to. Its already fixed in fixed in purposed PR. I have invested enough time on silly imports. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a2a347f to
1882f7a
Compare
There was an error while loading. Please reload this page.
|
Compared to main: (comment created at 2025-08-01 16:57:22+00:00 for 980137a) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
e6f17d1 to
54c5b1b
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
convention over configuration.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
54c5b1b to
aabd960
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
aabd960 to
18dec17
Compare
There was an error while loading. Please reload this page.
e0563a2 to
121f1bf
Compare
|
Ok, I've updated the PR now. I explicitly did not do this:
That should be really a separate issue/PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Do not report, if compareTo is not overridden locally, but only inherited.
Now that we only report on types, that have a compareTo() method, we should report on this method rather than on the entire class when equals and hashCode are missing.
Update code example for correct equals() implementation that uses compareTo() and is therefore automatically consistent.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a comma after the when clause in the message, otherwise looks good.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…rprone/OverrideBothEqualsAndHashCodeOnComparableRule.java Co-authored-by: Zbynek Konecny <[email protected]>
There was an error while loading. Please reload this page.
|
consider (potential) auto fix follow up: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
should just have named it like InconsistentComparable, CorruptComparableContract. This name is really long and kind of collides with best practise having the rule: big scope, small name. Which we have failed kind of. This reads like a private method name giving full detail, making the impl. obsolete to check. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
can not use it yet, as 17 released not in core, right? https://mvnrepository.com/artifact/net.sourceforge.pmd/pmd-core/7.16.0 when is this going to happen please? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[java] New Rule: OverrideBothEqualsAndHashCodeOnComparable
There was an error while loading. Please reload this page.