Skip to content

Detect EqualsUsingHashCode when hashCode results are stored in locals - #6019

Open
kalayciburak wants to merge 1 commit into
google:masterfrom
kalayciburak:fix/equals-using-hashcode-locals
Open

Detect EqualsUsingHashCode when hashCode results are stored in locals#6019
kalayciburak wants to merge 1 commit into
google:masterfrom
kalayciburak:fix/equals-using-hashcode-locals

Conversation

@kalayciburak

Copy link
Copy Markdown

Summary

EqualsUsingHashCode only recognized direct hashCode() comparisons inside the return expression. Runtime-equivalent equals methods that store both hash codes in locals and then compare those locals were missed (false negative).

This change tracks locals initialized solely from hashCode() (and not later reassigned) and reports when the terminal return condition is an equality comparison of only those hash-derived values. The existing terminal-condition behavior for && guards is preserved (hash comparison must be the rightmost/&& terminal part).

Fixes #5830

Test plan

  • mvn -pl core -am test -Dtest=EqualsUsingHashCodeTest -Dsurefire.failIfNoSpecifiedTests=false (JDK 21) — 6/6 GREEN
    • existing positive/negative cases
    • extracted locals positive
    • extracted locals with instanceof guard positive
    • extracted locals with additional field check negative

EqualsUsingHashCode previously only recognized direct hashCode()
comparisons in the return expression. Equivalent equals implementations
that extract both hash codes into locals before comparing them were
missed. Track locals initialized solely from hashCode() and flag when
the terminal return condition compares only those values.

Fixes google#5830
@google-cla

google-cla Bot commented Aug 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FN: EqualsUsingHashCode misses equals() that extracts hashCode() into locals

1 participant