JDK-4634392 : JDK code doesn't respect contract for equals and hashCode
  • Type: Bug
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 1.4.1,5.0,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_9
  • CPU: generic
  • Submitted: 2002-02-07
  • Updated: 2005-03-18
  • Resolved: 2005-03-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 betaFixed
Related Reports
Duplicate :  
Relates :  
Description
The following problem was originally reported in 4634068.

There are a number of classes that do not respect the
implied contract for equals and hashCode. See, for example,
Joshua Bloch's book "Effective Java", items 7-8.

sun.security.krb5.Realm defines
  equals(sun.security.krb5.Realm) but doesn't redefine
  equals(Object)
sun.security.krb5.internal.HostAddresses defines
  equals(sun.security.krb5.internal.HostAddresses) but doesn't redefine
  equals(Object)
sun.security.krb5.internal.KerberosTime defines
  equals(sun.security.krb5.internal.KerberosTime) but doesn't redefine
  equals(Object)
sun.security.krb5.internal.rcache.a9 redefines
  equals(Object) but not hashCode()
sun.security.x509.AVAComparator redefines
  equals(Object) but not hashCode()
sun.security.x509.EDIPartyName redefines
  equals(Object) but not hashCode()
sun.security.x509.GeneralName redefines
  equals(Object) but not hashCode()
sun.security.x509.GeneralSubtree redefines
  equals(Object) but not hashCode()
sun.security.x509.OtherName redefines
  equals(Object) but not
  hashCode()
sun.security.x509.PolicyInformation redefines
  equals(Object) but not
  hashCode()
sun.security.jgss.ProviderList$PreferencesEntry redefines
  equals(Object) but not
  hashCode()

Problems found by applying automatic tools to JDK
libraries. However, manual inspectation of the classes
reveals the same problems.

-- iag@sfbay 2002-02-06

Additional classes reported by a tool that applies similar checks:

sun.security.jgss.spi.GSSNameSpi-
equals signature is: (Lsun/security/jgss/spi/GSSNameSpi;)Z To override it has to be: (Ljava/lang/Object;)Z

sun.security.acl.AllPermissionsImpl -
equals signature is: (Ljava/security/acl/Permission;)Z To override it has to be: (Ljava/lang/Object;)Z

sun.security.acl.GroupImpl -
equals signature is: (Ljava/security/acl/Group;)Z To override it has to be: (Ljava/lang/Object;)Z

The classes listed above for not overriding hashCode method use hashCode method
from the class Object. Hence overriding hashCode is most likely required.

###@###.### 2002-10-30

Comments
EVALUATION GSSNameSpi presents some problems: 1. it is inconsistent - GSSName defines two versions of equals, and GSSNameSpi only defines one 2. it is confusing - the version of equals GSSNameSpi defines is the "wrong" version (it is not the version that takes an Object parameter) the current plan is to change GSSNameSpi so it defines two versions of equals, as well as hashCode. this makes it consistent with GSSName. since GSSNameSpi is a sun API this can be modified again in the future if necessary. for now it allows us to avoid seeing errors from tools like findBugs. ###@###.### 2004-12-15 00:36:25 GMT
15-12-2004

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
14-06-2004

WORK AROUND Should be fixed.
11-06-2004