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

SID::hashCode does not return same value for two equal objects #32

Open
rebeccaeaz opened this issue Dec 12, 2023 · 0 comments
Open

SID::hashCode does not return same value for two equal objects #32

rebeccaeaz opened this issue Dec 12, 2023 · 0 comments

Comments

@rebeccaeaz
Copy link

In Java:

Having two separated SIDs, that are equal, meaning:
sid1.equals(sid2) == true
And
sid2.equals(sid1) == true

Then, SID::hashCode does not generate the same hash for the two of them, despite being equal.
sid2.hashCode() != sid1.hashCode().
This breaks Java's contract for hashCode:
If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result

SID::hashCode implementation, within the SID library:

    public int hashCode() {
        int hash = 5;
        hash = 97 * hash + Arrays.hashCode(this.identifierAuthority);
        hash = 97 * hash + Objects.hashCode(this.subAuthorities);
        return hash;
    }

The problematic line is: Objects.hashCode(this.subAuthorities), which uses the default hashCode on each element which is the same for objects that are deep-equals.

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

No branches or pull requests

1 participant