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

Immutable.Map hashCode collision when swapping the boolean values in an object #1894

Open
brianshih1 opened this issue Feb 10, 2022 · 2 comments
Labels

Comments

@brianshih1
Copy link

brianshih1 commented Feb 10, 2022

What happened

I created two immutable.Map instances as follows:

const first = immutable.Map({ foo: true, valid: false })
const second = immutable.Map({ foo: false, valid: true })

These two objects have the same keys but swapped boolean values.

I noticed that they have the same hashCode. I would've assumed the hashCode is different since all I did is swap the boolean values for the two keys. This also seems to happen for these specific combination of words since the hashCode is different if I swap valid for bar.

How to reproduce

Create the two immutable.Map instances and look at the hashCode

@jdeniau jdeniau added the bug label Feb 15, 2022
@jdeniau
Copy link
Member

jdeniau commented Mar 2, 2022

hashCode might have a Collision according to the documentation

The "bug" was already present in 3.8.2 : https://runkit.com/jdeniau/621fd7b26f5ba1000804a031

To be honest, the hashCode implementation is pretty obscure to me and I really do not know how to fix that without possible side effects.

@Skywalker13
Copy link

Use equals() instead of the hashCode if you want to compare both immutable objects.

Skywalker13 added a commit to Xcraft-Inc/xcraft-core-goblin that referenced this issue Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants