Skip to content
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

Replace usages of identityHashCode to prevent collisions #6512

Merged
merged 1 commit into from
Nov 12, 2021

Conversation

yawkat
Copy link
Member

@yawkat yawkat commented Nov 12, 2021

System.identityHashCode is, by default, set to a random int by the JVM. Using it as a map key could lead to collisions. This patch replaces those usages with a new wrapper class that, on top of the identityHashCode for hashing, uses == for the equals check. This prevents any collisions in the map keys.

There is unfortunately no way to test for these collisions without a JVM option (-XX:hashCode), so there is no unit test in this patch.

System.identityHashCode is, by default, set to a random int by the JVM. Using it as a map key could lead to collisions. This patch replaces those usages with a new wrapper class that, on top of the identityHashCode for hashing, uses == for the equals check. This prevents any collisions in the map keys.

There is unfortunately no way to test for these collisions without a JVM option (-XX:hashCode), so there is no unit test in this patch.
@yawkat yawkat added the type: improvement A minor improvement to an existing feature label Nov 12, 2021
@yawkat yawkat added this to the 3.1.4 milestone Nov 12, 2021
@jameskleeh jameskleeh merged commit 21f79f7 into 3.1.x Nov 12, 2021
@jameskleeh jameskleeh deleted the identity-0 branch November 12, 2021 16:32
dstepanov pushed a commit to konrad-kaminski/micronaut-core that referenced this pull request Nov 22, 2021
…rojects#6512)

System.identityHashCode is, by default, set to a random int by the JVM. Using it as a map key could lead to collisions. This patch replaces those usages with a new wrapper class that, on top of the identityHashCode for hashing, uses == for the equals check. This prevents any collisions in the map keys.

There is unfortunately no way to test for these collisions without a JVM option (-XX:hashCode), so there is no unit test in this patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants