JDK-7041252 : Use j.u.Objects.equals in security classes
  • Type: Bug
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-05-02
  • Updated: 2019-08-27
  • Resolved: 2011-07-06
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 8
8 b01Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
In JDK 7, the java.util.Objects class with added with a two-argument equals method.  Various security classes seem to have instances of this logic which could be replaced by calls to the library method instead.

Comments
not verified since the label has noreg-refactor
08-01-2013

PUBLIC COMMENTS See http://hg.openjdk.java.net/jdk8/tl/jdk/rev/33e6291f3251
15-06-2011

SUGGESTED FIX # HG changeset patch # User darcy # Date 1308152231 25200 # Node ID 33e6291f3251dfad30eb6692409e6ccc2c8f39ba # Parent 4e7a9fa84dea807567785921bf61906fdab80823 7041252: Use j.u.Objects.equals in security classes Reviewed-by: weijun --- a/src/share/classes/sun/security/tools/KeyTool.java Tue Jun 14 12:31:31 2011 -0700 +++ b/src/share/classes/sun/security/tools/KeyTool.java Wed Jun 15 08:37:11 2011 -0700 @@ -4193,15 +4193,11 @@ class Pair<A, B> { 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() { --- a/src/share/classes/sun/security/x509/DistributionPoint.java Tue Jun 14 12:31:31 2011 -0700 +++ b/src/share/classes/sun/security/x509/DistributionPoint.java Wed Jun 15 08:37:11 2011 -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 @@ public class DistributionPoint { } /** - * 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 @@ public class DistributionPoint { } 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; } --- a/src/share/classes/sun/security/x509/DistributionPointName.java Tue Jun 14 12:31:31 2011 -0700 +++ b/src/share/classes/sun/security/x509/DistributionPointName.java Wed Jun 15 08:37:11 2011 -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 @@ public class DistributionPointName { } 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 @@ public class DistributionPointName { 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); - } }
15-06-2011

EVALUATION A fine idea.
02-05-2011