You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the smallest, simplest way to reproduce the problem?
EqualsAvoidsNull is intended to only improve comparisons with null. However, it unconditionally inverts a.compareTo(b) even for non-null arguments. That's completely wrong (because compareTo() implements an ordered comparison), but unfortunately the refactored code still compiles.
What did you expect to see?
Existing unit tests are wrong and would uncover this issue, if the expectation is fixed. See for example
Perhaps these cases should have been split off into a separate issue so as to not confuse the purpose of EqualsAvoidsNull, nor invert the comparison accidentally.
What is the smallest, simplest way to reproduce the problem?
EqualsAvoidsNull is intended to only improve comparisons with null. However, it unconditionally inverts a.compareTo(b) even for non-null arguments. That's completely wrong (because compareTo() implements an ordered comparison), but unfortunately the refactored code still compiles.
What did you expect to see?
Existing unit tests are wrong and would uncover this issue, if the expectation is fixed. See for example
rewrite-static-analysis/src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java
Lines 49 to 62 in 3609cd7
s.compareTo("test")
is not the same as"test".compareTo(s)
.Are you interested in contributing a fix to OpenRewrite?
I would just remove the 2 compareTo* matchers, not sure if that is the best fix.
The text was updated successfully, but these errors were encountered: