From 3153fa5ba15d402b4729a649737d02eead5a5064 Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Fri, 15 Jun 2012 03:09:57 -0500 Subject: Fixed equals() and hashCode() in X500Name and RDN. The X500Name and RDN have been modified to fix the incorrect method signature for equals() and the missing hashCode(). Ticket #206 --- base/util/src/netscape/security/x509/X500Name.java | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'base/util/src/netscape/security/x509/X500Name.java') diff --git a/base/util/src/netscape/security/x509/X500Name.java b/base/util/src/netscape/security/x509/X500Name.java index c2886dab2..d0111a27e 100644 --- a/base/util/src/netscape/security/x509/X500Name.java +++ b/base/util/src/netscape/security/x509/X500Name.java @@ -19,6 +19,7 @@ package netscape.security.x509; import java.io.IOException; import java.security.Principal; +import java.util.Arrays; import java.util.Enumeration; import java.util.Vector; @@ -285,23 +286,25 @@ public class X500Name implements Principal, GeneralNameInterface { } } - /** - * Compares this name with another, for equality. - * - * @return true iff the names are identical. - */ - synchronized public boolean equals(X500Name other) { - int i; + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(names); + return result; + } - if (this == other) + @Override + public boolean equals(Object obj) { + if (this == obj) return true; - - if (names.length != other.names.length) + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + X500Name other = (X500Name) obj; + if (!Arrays.equals(names, other.names)) return false; - for (i = 0; i < names.length; i++) { - if (!names[i].equals(other.names[i])) - return false; - } return true; } -- cgit