Code review request for 7041252 Use j.u.Objects.equals in security classes

Joe Darcy joe.darcy at oracle.com
Wed Jun 15 02:28:55 UTC 2011


Hello.

Please review this change to replace use of private two-argument equals 
methods with the platform Objects.equals method introduced in JDK 7:

    7041252 Use j.u.Objects.equals in security classes
    http://cr.openjdk.java.net/~darcy/7041252.0/

Patch below.

I ran the java/security and sun/security tests with this patch and they 
all pass except for sun/security/pkcs11/KeyAgreement/TestDH.java.  
However, that test also fails for me on a build without this change.

Thanks,

-Joe

--- old/src/share/classes/sun/security/tools/KeyTool.java    2011-06-14 
18:20:09.000000000 -0700
+++ new/src/share/classes/sun/security/tools/KeyTool.java    2011-06-14 
18:20:09.000000000 -0700
@@ -4193,15 +4193,11 @@
         return "Pair[" + fst + "," + snd + "]";
     }
 
-    private static boolean equals(Object x, Object y) {
-        return (x == null && y == null) || (x != null && x.equals(y));
-    }
-
     public boolean equals(Object other) {
         return
             other instanceof Pair &&
-            equals(fst, ((Pair)other).fst) &&
-            equals(snd, ((Pair)other).snd);
+            Objects.equals(fst, ((Pair)other).fst) &&
+            Objects.equals(snd, ((Pair)other).snd);
     }
 
     public int hashCode() {
--- old/src/share/classes/sun/security/x509/DistributionPoint.java    
2011-06-14 18:20:10.000000000 -0700
+++ new/src/share/classes/sun/security/x509/DistributionPoint.java    
2011-06-14 18:20:10.000000000 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights 
reserved.
+ * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights 
reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -319,13 +319,6 @@
     }
 
     /**
-     * Utility function for a.equals(b) where both a and b may be null.
-     */
-    private static boolean equals(Object a, Object b) {
-        return (a == null) ? (b == null) : a.equals(b);
-    }
-
-    /**
      * Compare an object to this DistributionPoint for equality.
      *
      * @param obj Object to be compared to this
@@ -340,9 +333,9 @@
         }
         DistributionPoint other = (DistributionPoint)obj;
 
-        boolean equal = equals(this.fullName, other.fullName)
-                     && equals(this.relativeName, other.relativeName)
-                     && equals(this.crlIssuer, other.crlIssuer)
+        boolean equal = Objects.equals(this.fullName, other.fullName)
+                     && Objects.equals(this.relativeName, 
other.relativeName)
+                     && Objects.equals(this.crlIssuer, other.crlIssuer)
                      && Arrays.equals(this.reasonFlags, other.reasonFlags);
         return equal;
     }
--- 
old/src/share/classes/sun/security/x509/DistributionPointName.java    
2011-06-14 18:20:11.000000000 -0700
+++ 
new/src/share/classes/sun/security/x509/DistributionPointName.java    
2011-06-14 18:20:10.000000000 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights 
reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -201,8 +201,8 @@
         }
         DistributionPointName other = (DistributionPointName)obj;
 
-        return equals(this.fullName, other.fullName) &&
-               equals(this.relativeName, other.relativeName);
+        return Objects.equals(this.fullName, other.fullName) &&
+               Objects.equals(this.relativeName, other.relativeName);
     }
 
     /**
@@ -239,11 +239,4 @@
 
         return sb.toString();
     }
-
-    /*
-     * Utility function for a.equals(b) where both a and b may be null.
-     */
-    private static boolean equals(Object a, Object b) {
-        return (a == null) ? (b == null) : a.equals(b);
-    }
 }




More information about the security-dev mailing list