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
DoubleLiteral.java:[37,30] [ObjectEqualsForPrimitives] Avoid unnecessary boxing by using plain == for primitive types.
[ERROR] (see https://errorprone.info/bugpattern/ObjectEqualsForPrimitives)
[ERROR] Did you mean 'return (value == that.value);'?
That changes semantics -- different result when both compared values are NaN. Object Equals should be value based and generally should compare NaNs as equal.
It's probably worth noting that equals generated for Java record classes also compares NaN values as equal (as if Objects.equals was used).
Therefore ObjectEqualsForPrimitives should not suggest ==, but it should suggest Double.compare(...) == 0 instead.
The text was updated successfully, but these errors were encountered:
`Objects.equal(a_double, another_double)` and `a_double == another_double` have different semantics (different result when both compared values are NaN). This is especially relevant when implementing `equals` methods.
Fixes#4392Fixes#4394
FUTURE_COPYBARA_INTEGRATE_REVIEW=#4394 from findepi:findepi/double-compare 603b9c6
PiperOrigin-RevId: 634390506
for a class like
ObjectEqualsForPrimitives
' current suggestion is:That changes semantics -- different result when both compared values are NaN. Object Equals should be value based and generally should compare NaNs as equal.
It's probably worth noting that equals generated for Java record classes also compares NaN values as equal (as if Objects.equals was used).
Therefore
ObjectEqualsForPrimitives
should not suggest==
, but it should suggestDouble.compare(...) == 0
instead.The text was updated successfully, but these errors were encountered: