Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SEC-1141: ObjectIdentityImpl has incorrect hashCode implementation #1389

spring-issuemaster opened this Issue Apr 17, 2009 · 1 comment


None yet
1 participant

Scott Pardy(Migrated from SEC-1141) said:

The ObjectIdentityImpl class contains a bug in it’s hashCode implementation. 2 objects which are equal to each other using the ‘.equals()’ method do not neccesarily produce the same hashcode. Consider the following code:

ObjectIdentityImpl oi1 = new ObjectIdentityImpl(“java.lang.String”, “10”);
ObjectIdentityImpl oi2 = new ObjectIdentityImpl(“java.lang.String”, 10);
System.out.println(oi1.equals(oi2)); //true
System.out.println(oi1.hashCode() == oi2.hashCode()); //false
System.out.println(oi1.hashCode()); //25246124
System.out.println(oi2.hashCode()); //25247673

This is due to the use of ‘this.identifier.hashCode()’ (line 146 ObjectIdentityImpl), while the equals method uses ‘this.getIdentifier().toString().equals(other.getIdentifier().toString()’ (line 123 ObjectIdentityImpl)

Luke Taylor said:

The simplest solution here seems to be to remove the use of toString() from the equals method. I've also updated it so that identifiers which are of type Numeric (realistically Integers and Longs) are considered equal if they have the same numeric value.

@spring-issuemaster spring-issuemaster added this to the 3.0.0 M1 milestone Feb 5, 2016

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