diff --git a/src/java.base/share/classes/com/sun/crypto/provider/DESKey.java b/src/java.base/share/classes/com/sun/crypto/provider/DESKey.java index 21e7247e87b..2550556bbad 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/DESKey.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/DESKey.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -29,6 +29,7 @@ import java.lang.ref.Reference; import java.security.MessageDigest; import java.security.KeyRep; import java.security.InvalidKeyException; +import java.util.Arrays; import javax.crypto.SecretKey; import javax.crypto.spec.DESKeySpec; @@ -108,26 +109,24 @@ final class DESKey implements SecretKey { * Calculates a hash code value for the object. * Objects that are equal will also have the same hashcode. */ + @Override public int hashCode() { - int retval = 0; - for (int i = 1; i < this.key.length; i++) { - retval += this.key[i] * i; - } - return(retval ^= "des".hashCode()); + return Arrays.hashCode(this.key) ^ "des".hashCode(); } + @Override public boolean equals(Object obj) { if (this == obj) return true; - if (!(obj instanceof SecretKey)) + if (!(obj instanceof SecretKey that)) return false; - String thatAlg = ((SecretKey)obj).getAlgorithm(); + String thatAlg = that.getAlgorithm(); if (!(thatAlg.equalsIgnoreCase("DES"))) return false; - byte[] thatKey = ((SecretKey)obj).getEncoded(); + byte[] thatKey = that.getEncoded(); boolean ret = MessageDigest.isEqual(this.key, thatKey); java.util.Arrays.fill(thatKey, (byte)0x00); return ret; diff --git a/src/java.base/share/classes/com/sun/crypto/provider/DESedeKey.java b/src/java.base/share/classes/com/sun/crypto/provider/DESedeKey.java index 2847f305017..7e075343abd 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/DESedeKey.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/DESedeKey.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -29,6 +29,7 @@ import java.lang.ref.Reference; import java.security.MessageDigest; import java.security.KeyRep; import java.security.InvalidKeyException; +import java.util.Arrays; import javax.crypto.SecretKey; import javax.crypto.spec.DESedeKeySpec; @@ -107,27 +108,25 @@ final class DESedeKey implements SecretKey { * Calculates a hash code value for the object. * Objects that are equal will also have the same hashcode. */ + @Override public int hashCode() { - int retval = 0; - for (int i = 1; i < this.key.length; i++) { - retval += this.key[i] * i; - } - return(retval ^= "desede".hashCode()); + return Arrays.hashCode(this.key) ^ "desede".hashCode(); } + @Override public boolean equals(Object obj) { if (this == obj) return true; - if (!(obj instanceof SecretKey)) + if (!(obj instanceof SecretKey that)) return false; - String thatAlg = ((SecretKey)obj).getAlgorithm(); + String thatAlg = that.getAlgorithm(); if (!(thatAlg.equalsIgnoreCase("DESede")) && !(thatAlg.equalsIgnoreCase("TripleDES"))) return false; - byte[] thatKey = ((SecretKey)obj).getEncoded(); + byte[] thatKey = that.getEncoded(); boolean ret = MessageDigest.isEqual(this.key, thatKey); java.util.Arrays.fill(thatKey, (byte)0x00); return ret; diff --git a/src/java.base/share/classes/com/sun/crypto/provider/DHPrivateKey.java b/src/java.base/share/classes/com/sun/crypto/provider/DHPrivateKey.java index c2c8348fffa..6d908721b4a 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/DHPrivateKey.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/DHPrivateKey.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -287,18 +287,18 @@ final class DHPrivateKey implements PrivateKey, * Calculates a hash code value for the object. * Objects that are equal will also have the same hashcode. */ + @Override public int hashCode() { return Objects.hash(x, p, g); } + @Override public boolean equals(Object obj) { if (this == obj) return true; - if (!(obj instanceof javax.crypto.interfaces.DHPrivateKey)) { + if (!(obj instanceof javax.crypto.interfaces.DHPrivateKey other)) { return false; } - javax.crypto.interfaces.DHPrivateKey other = - (javax.crypto.interfaces.DHPrivateKey) obj; DHParameterSpec otherParams = other.getParams(); return ((this.x.compareTo(other.getX()) == 0) && (this.p.compareTo(otherParams.getP()) == 0) && diff --git a/src/java.base/share/classes/com/sun/crypto/provider/DHPublicKey.java b/src/java.base/share/classes/com/sun/crypto/provider/DHPublicKey.java index c786743aab0..78d7d71b1c1 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/DHPublicKey.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/DHPublicKey.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -279,19 +279,19 @@ javax.crypto.interfaces.DHPublicKey, Serializable { * Calculates a hash code value for the object. * Objects that are equal will also have the same hashcode. */ + @Override public int hashCode() { return Objects.hash(y, p, g); } + @Override public boolean equals(Object obj) { if (this == obj) return true; - if (!(obj instanceof javax.crypto.interfaces.DHPublicKey)) { + if (!(obj instanceof javax.crypto.interfaces.DHPublicKey other)) { return false; } - javax.crypto.interfaces.DHPublicKey other = - (javax.crypto.interfaces.DHPublicKey) obj; DHParameterSpec otherParams = other.getParams(); return ((this.y.compareTo(other.getY()) == 0) && (this.p.compareTo(otherParams.getP()) == 0) && diff --git a/src/java.base/share/classes/com/sun/crypto/provider/PBEKey.java b/src/java.base/share/classes/com/sun/crypto/provider/PBEKey.java index 15c9c1f3d59..dba3cccf193 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/PBEKey.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/PBEKey.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -105,23 +105,20 @@ final class PBEKey implements SecretKey { * Calculates a hash code value for the object. * Objects that are equal will also have the same hashcode. */ + @Override public int hashCode() { - int retval = 0; - for (int i = 1; i < this.key.length; i++) { - retval += this.key[i] * i; - } - return(retval ^= getAlgorithm().toLowerCase(Locale.ENGLISH).hashCode()); + return Arrays.hashCode(this.key) + ^ getAlgorithm().toLowerCase(Locale.ENGLISH).hashCode(); } + @Override public boolean equals(Object obj) { if (obj == this) return true; - if (!(obj instanceof SecretKey)) + if (!(obj instanceof SecretKey that)) return false; - SecretKey that = (SecretKey)obj; - if (!(that.getAlgorithm().equalsIgnoreCase(type))) return false; diff --git a/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java b/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java index 5815b5ca063..445a8a1814c 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java @@ -165,7 +165,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { @Override public boolean equals(Object obj) { if (this == obj) return true; - if (this.getClass() != obj.getClass()) return false; + if (obj == null || this.getClass() != obj.getClass()) return false; SecretKey sk = (SecretKey)obj; return prf.getAlgorithm().equalsIgnoreCase( sk.getAlgorithm()) && @@ -247,32 +247,28 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { * Calculates a hash code value for the object. * Objects that are equal will also have the same hashcode. */ + @Override public int hashCode() { try { - int retval = 0; - for (int i = 1; i < this.key.length; i++) { - retval += this.key[i] * i; - } - return (retval ^= getAlgorithm().toLowerCase - (Locale.ENGLISH).hashCode()); + return Arrays.hashCode(this.key) + ^ getAlgorithm().toLowerCase(Locale.ENGLISH).hashCode(); } finally { // prevent this from being cleaned for the above block Reference.reachabilityFence(this); } } + @Override public boolean equals(Object obj) { try { if (obj == this) { return true; } - if (!(obj instanceof SecretKey)) { + if (!(obj instanceof SecretKey that)) { return false; } - SecretKey that = (SecretKey) obj; - if (!(that.getAlgorithm().equalsIgnoreCase(getAlgorithm()))) { return false; } diff --git a/src/java.base/share/classes/java/security/AccessControlContext.java b/src/java.base/share/classes/java/security/AccessControlContext.java index eb893c0d021..6c75d890f07 100644 --- a/src/java.base/share/classes/java/security/AccessControlContext.java +++ b/src/java.base/share/classes/java/security/AccessControlContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -764,6 +764,7 @@ public final class AccessControlContext { * and has the same set of {@code ProtectionDomain} objects as this context, * {@code false} otherwise. */ + @Override public boolean equals(Object obj) { if (obj == this) return true; @@ -940,22 +941,20 @@ public final class AccessControlContext { /** - * Returns the hash code value for this context. The hash code - * is computed by exclusive or-ing the hash code of all the protection - * domains in the context together. - * - * @return a hash code value for this context. + * {@return the hash code value for this context} + * The hash code is computed by exclusive or-ing the hash code of all the + * protection domains in the context together. */ - + @Override public int hashCode() { int hashCode = 0; if (context == null) return hashCode; - for (int i =0; i < context.length; i++) { - if (context[i] != null) - hashCode ^= context[i].hashCode(); + for (ProtectionDomain protectionDomain : context) { + if (protectionDomain != null) + hashCode ^= protectionDomain.hashCode(); } return hashCode; diff --git a/src/java.base/share/classes/java/security/AllPermission.java b/src/java.base/share/classes/java/security/AllPermission.java index 3587bc91795..c93e60fb913 100644 --- a/src/java.base/share/classes/java/security/AllPermission.java +++ b/src/java.base/share/classes/java/security/AllPermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2023, 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 @@ -98,16 +98,15 @@ public final class AllPermission extends Permission { * @param obj the object we are testing for equality with this object. * @return true if {@code obj} is an {@code AllPermission}, false otherwise. */ + @Override public boolean equals(Object obj) { return (obj instanceof AllPermission); } /** - * Returns the hash code value for this object. - * - * @return a hash code value for this object. + * {@return the hash code value for this object} */ - + @Override public int hashCode() { return 1; } diff --git a/src/java.base/share/classes/java/security/BasicPermission.java b/src/java.base/share/classes/java/security/BasicPermission.java index 817a343f7f2..7dc34d54622 100644 --- a/src/java.base/share/classes/java/security/BasicPermission.java +++ b/src/java.base/share/classes/java/security/BasicPermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -217,12 +217,10 @@ public abstract class BasicPermission extends Permission /** - * Returns the hash code value for this object. + * {@return the hash code value for this object} * The hash code used is the hash code of the name, that is, * {@code getName().hashCode()}, where {@code getName} is * from the {@code Permission} superclass. - * - * @return a hash code value for this object. */ @Override public int hashCode() { diff --git a/src/java.base/share/classes/java/security/CodeSigner.java b/src/java.base/share/classes/java/security/CodeSigner.java index c1d0615ceaa..76c8be058ba 100644 --- a/src/java.base/share/classes/java/security/CodeSigner.java +++ b/src/java.base/share/classes/java/security/CodeSigner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2023, 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 @@ -27,6 +27,7 @@ package java.security; import java.io.*; import java.security.cert.CertPath; +import java.util.Objects; /** * This class encapsulates information about a code signer. @@ -98,19 +99,14 @@ public final class CodeSigner implements Serializable { } /** - * Returns the hash code value for this code signer. + * {@return the hash code value for this code signer} * The hash code is generated using the signer's certificate path and the * timestamp, if present. - * - * @return a hash code value for this code signer. */ + @Override public int hashCode() { if (myhash == -1) { - if (timestamp == null) { - myhash = signerCertPath.hashCode(); - } else { - myhash = signerCertPath.hashCode() + timestamp.hashCode(); - } + myhash = signerCertPath.hashCode() + Objects.hashCode(timestamp); } return myhash; } @@ -126,25 +122,15 @@ public final class CodeSigner implements Serializable { * @return {@code true} if the objects are considered equal, * {@code false} otherwise. */ + @Override public boolean equals(Object obj) { - if ((!(obj instanceof CodeSigner that))) { - return false; - } - - if (this == that) { + if (this == obj) { return true; } - Timestamp thatTimestamp = that.getTimestamp(); - if (timestamp == null) { - if (thatTimestamp != null) { - return false; - } - } else { - if ((!timestamp.equals(thatTimestamp))) { - return false; - } - } - return signerCertPath.equals(that.getSignerCertPath()); + + return obj instanceof CodeSigner other + && Objects.equals(timestamp, other.getTimestamp()) + && signerCertPath.equals(other.getSignerCertPath()); } /** diff --git a/src/java.base/share/classes/java/security/CodeSource.java b/src/java.base/share/classes/java/security/CodeSource.java index 5c787ac3b04..b1cf0bf3c7d 100644 --- a/src/java.base/share/classes/java/security/CodeSource.java +++ b/src/java.base/share/classes/java/security/CodeSource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -130,16 +130,11 @@ public class CodeSource implements java.io.Serializable { } /** - * Returns the hash code value for this object. - * - * @return a hash code value for this object. + * {@return the hash code value for this object} */ @Override public int hashCode() { - if (location != null) - return location.hashCode(); - else - return 0; + return Objects.hashCode(location); } /** diff --git a/src/java.base/share/classes/java/security/Identity.java b/src/java.base/share/classes/java/security/Identity.java index ffe44f236f2..06a981d3e7c 100644 --- a/src/java.base/share/classes/java/security/Identity.java +++ b/src/java.base/share/classes/java/security/Identity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, 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 @@ -336,6 +336,7 @@ public abstract class Identity implements Principal, Serializable { * * @see #identityEquals */ + @Override public final boolean equals(Object identity) { if (identity == this) { return true; @@ -478,10 +479,9 @@ public abstract class Identity implements Principal, Serializable { } /** - * Returns a hashcode for this {@code Identity}. - * - * @return a hashcode for this {@code Identity}. + * {@return the hashcode for this {@code Identity}} */ + @Override public int hashCode() { return name.hashCode(); } diff --git a/src/java.base/share/classes/java/security/PKCS12Attribute.java b/src/java.base/share/classes/java/security/PKCS12Attribute.java index 3b2a649eda6..114660c06f8 100644 --- a/src/java.base/share/classes/java/security/PKCS12Attribute.java +++ b/src/java.base/share/classes/java/security/PKCS12Attribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -196,17 +196,13 @@ public final class PKCS12Attribute implements KeyStore.Entry.Attribute { if (this == obj) { return true; } - if (!(obj instanceof PKCS12Attribute)) { - return false; - } - return Arrays.equals(encoded, ((PKCS12Attribute) obj).encoded); + return obj instanceof PKCS12Attribute other + && Arrays.equals(encoded, other.encoded); } /** - * Returns the hashcode for this {@code PKCS12Attribute}. + * {@return the hashcode for this {@code PKCS12Attribute}} * The hash code is computed from its DER encoding. - * - * @return the hash code */ @Override public int hashCode() { diff --git a/src/java.base/share/classes/java/security/Permission.java b/src/java.base/share/classes/java/security/Permission.java index fa5755e5a80..f5d27681bda 100644 --- a/src/java.base/share/classes/java/security/Permission.java +++ b/src/java.base/share/classes/java/security/Permission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -138,7 +138,7 @@ public abstract class Permission implements Guard, java.io.Serializable { * * @return {@code true} if both {@code Permission} objects are equivalent. */ - + @Override public abstract boolean equals(Object obj); /** @@ -161,7 +161,7 @@ public abstract class Permission implements Guard, java.io.Serializable { * * @return a hash code value for this object. */ - + @Override public abstract int hashCode(); /** diff --git a/src/java.base/share/classes/java/security/Principal.java b/src/java.base/share/classes/java/security/Principal.java index 0b3466cf768..a5b4620be77 100644 --- a/src/java.base/share/classes/java/security/Principal.java +++ b/src/java.base/share/classes/java/security/Principal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, 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 @@ -50,6 +50,7 @@ public interface Principal { * @return {@code true} if the {@code Principal} passed in is the same as * that encapsulated by this {@code Principal}, and {@code false} otherwise. */ + @Override boolean equals(Object another); /** @@ -60,10 +61,9 @@ public interface Principal { String toString(); /** - * Returns a hashcode for this {@code Principal}. - * - * @return a hashcode for this {@code Principal}. + * {@return a hashcode for this {@code Principal}} */ + @Override int hashCode(); /** diff --git a/src/java.base/share/classes/java/security/SecureClassLoader.java b/src/java.base/share/classes/java/security/SecureClassLoader.java index 682edf8e148..0a649ab7227 100644 --- a/src/java.base/share/classes/java/security/SecureClassLoader.java +++ b/src/java.base/share/classes/java/security/SecureClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -240,8 +240,7 @@ public class SecureClassLoader extends ClassLoader { @Override public int hashCode() { - String locationNoFrag = cs.getLocationNoFragString(); - return locationNoFrag != null ? locationNoFrag.hashCode() : 0; + return Objects.hashCode(cs.getLocationNoFragString()); } @Override diff --git a/src/java.base/share/classes/java/security/UnresolvedPermission.java b/src/java.base/share/classes/java/security/UnresolvedPermission.java index f1c2461c792..54d5a60d105 100644 --- a/src/java.base/share/classes/java/security/UnresolvedPermission.java +++ b/src/java.base/share/classes/java/security/UnresolvedPermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -35,6 +35,7 @@ import java.util.Hashtable; import java.lang.reflect.*; import java.security.cert.*; import java.util.List; +import java.util.Objects; /** * The {@code UnresolvedPermission} class is used to hold Permissions that @@ -349,23 +350,13 @@ implements java.io.Serializable } // check name - if (this.name == null) { - if (that.name != null) { - return false; - } - } else if (!this.name.equals(that.name)) { + if (!Objects.equals(this.name, that.name)) { return false; } // check actions - if (this.actions == null) { - if (that.actions != null) { - return false; - } - } else { - if (!this.actions.equals(that.actions)) { - return false; - } + if (!Objects.equals(this.actions, that.actions)) { + return false; } // check certs @@ -404,18 +395,11 @@ implements java.io.Serializable } /** - * Returns the hash code value for this object. - * - * @return a hash code value for this object. + * {@return the hash code value for this object} */ @Override public int hashCode() { - int hash = type.hashCode(); - if (name != null) - hash ^= name.hashCode(); - if (actions != null) - hash ^= actions.hashCode(); - return hash; + return Objects.hash(type, name, actions); } /** diff --git a/src/java.base/share/classes/java/security/cert/CertPath.java b/src/java.base/share/classes/java/security/cert/CertPath.java index fc4bdc6a689..80e68d1c598 100644 --- a/src/java.base/share/classes/java/security/cert/CertPath.java +++ b/src/java.base/share/classes/java/security/cert/CertPath.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2023, 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 @@ -177,19 +177,20 @@ public abstract class CertPath implements Serializable { * @return true if the specified object is equal to this certification path, * false otherwise */ + @Override public boolean equals(Object other) { if (this == other) return true; return other instanceof CertPath that - && that.getType().equals(this.type) + && this.type.equals(that.getType()) && this.getCertificates().equals(that.getCertificates()); } /** - * Returns the hashcode for this certification path. The hash code of - * a certification path is defined to be the result of the following - * calculation: + * {@return the hashcode value for this certification path} + * The hash code of a certification path is defined to be the result of + * the following calculation: *
{@code
* hashCode = path.getType().hashCode();
* hashCode = 31*hashCode + path.getCertificates().hashCode();
@@ -198,9 +199,8 @@ public abstract class CertPath implements Serializable {
* {@code path1.hashCode()==path2.hashCode()} for any two certification
* paths, {@code path1} and {@code path2}, as required by the
* general contract of {@code Object.hashCode}.
- *
- * @return the hashcode value for this certification path
*/
+ @Override
public int hashCode() {
int hashCode = type.hashCode();
hashCode = 31*hashCode + getCertificates().hashCode();
diff --git a/src/java.base/share/classes/java/security/cert/Certificate.java b/src/java.base/share/classes/java/security/cert/Certificate.java
index 1e61fdf2af4..1e212f644b3 100644
--- a/src/java.base/share/classes/java/security/cert/Certificate.java
+++ b/src/java.base/share/classes/java/security/cert/Certificate.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -104,6 +104,7 @@ public abstract class Certificate implements java.io.Serializable {
* @return true iff the encoded forms of the two certificates
* match, false otherwise.
*/
+ @Override
public boolean equals(Object other) {
if (this == other) {
return true;
@@ -122,11 +123,10 @@ public abstract class Certificate implements java.io.Serializable {
}
/**
- * Returns a hashcode value for this certificate from its
- * encoded form.
- *
- * @return the hashcode value.
+ * {@return the hashcode value for this certificate from its
+ * encoded form}
*/
+ @Override
public int hashCode() {
int h = hash;
if (h == -1) {
diff --git a/src/java.base/share/classes/java/security/cert/URICertStoreParameters.java b/src/java.base/share/classes/java/security/cert/URICertStoreParameters.java
index 094a370c4b8..b73383cf3d5 100644
--- a/src/java.base/share/classes/java/security/cert/URICertStoreParameters.java
+++ b/src/java.base/share/classes/java/security/cert/URICertStoreParameters.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2023, 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
@@ -100,10 +100,8 @@ public final class URICertStoreParameters implements CertStoreParameters {
}
/**
- * Returns a hash code value for this parameters object.
+ * {@return a hash code value for this parameters object}
* The hash code is generated using the URI supplied at construction.
- *
- * @return a hash code value for this parameters object.
*/
@Override
public int hashCode() {
diff --git a/src/java.base/share/classes/java/security/cert/X509CRL.java b/src/java.base/share/classes/java/security/cert/X509CRL.java
index f014c9b82c8..ddb622af1fe 100644
--- a/src/java.base/share/classes/java/security/cert/X509CRL.java
+++ b/src/java.base/share/classes/java/security/cert/X509CRL.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -127,6 +127,7 @@ public abstract class X509CRL extends CRL implements X509Extension {
* @return true iff the encoded forms of the two CRLs
* match, false otherwise.
*/
+ @Override
public boolean equals(Object other) {
if (this == other) {
return true;
@@ -145,19 +146,15 @@ public abstract class X509CRL extends CRL implements X509Extension {
}
/**
- * Returns a hashcode value for this CRL from its
- * encoded form.
- *
- * @return the hashcode value.
+ * {@return a hashcode value for this CRL from its
+ * encoded form}
*/
+ @Override
public int hashCode() {
int retval = 0;
try {
byte[] crlData = X509CRLImpl.getEncodedInternal(this);
- for (int i = 1; i < crlData.length; i++) {
- retval += crlData[i] * i;
- }
- return retval;
+ return Arrays.hashCode(crlData);
} catch (CRLException e) {
return retval;
}
diff --git a/src/java.base/share/classes/java/security/cert/X509CRLEntry.java b/src/java.base/share/classes/java/security/cert/X509CRLEntry.java
index a02e414c429..bcb22e870ee 100644
--- a/src/java.base/share/classes/java/security/cert/X509CRLEntry.java
+++ b/src/java.base/share/classes/java/security/cert/X509CRLEntry.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -26,6 +26,7 @@
package java.security.cert;
import java.math.BigInteger;
+import java.util.Arrays;
import java.util.Date;
import javax.security.auth.x500.X500Principal;
@@ -83,6 +84,7 @@ public abstract class X509CRLEntry implements X509Extension {
* @return true iff the encoded forms of the two CRL entries
* match, false otherwise.
*/
+ @Override
public boolean equals(Object other) {
if (this == other)
return true;
@@ -92,34 +94,23 @@ public abstract class X509CRLEntry implements X509Extension {
byte[] thisCRLEntry = this.getEncoded();
byte[] otherCRLEntry = ((X509CRLEntry)other).getEncoded();
- if (thisCRLEntry.length != otherCRLEntry.length)
- return false;
- for (int i = 0; i < thisCRLEntry.length; i++)
- if (thisCRLEntry[i] != otherCRLEntry[i])
- return false;
+ return Arrays.equals(thisCRLEntry, otherCRLEntry);
} catch (CRLException ce) {
return false;
}
- return true;
}
/**
- * Returns a hashcode value for this CRL entry from its
- * encoded form.
- *
- * @return the hashcode value.
+ * {@return the hashcode value for this CRL entry from its
+ * encoded form}
*/
+ @Override
public int hashCode() {
- int retval = 0;
try {
- byte[] entryData = this.getEncoded();
- for (int i = 1; i < entryData.length; i++)
- retval += entryData[i] * i;
-
+ return Arrays.hashCode(this.getEncoded());
} catch (CRLException ce) {
- return(retval);
+ return 0;
}
- return(retval);
}
/**
diff --git a/src/java.base/share/classes/java/security/spec/ECFieldF2m.java b/src/java.base/share/classes/java/security/spec/ECFieldF2m.java
index acc17d60194..57894b50244 100644
--- a/src/java.base/share/classes/java/security/spec/ECFieldF2m.java
+++ b/src/java.base/share/classes/java/security/spec/ECFieldF2m.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, 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
@@ -26,6 +26,7 @@ package java.security.spec;
import java.math.BigInteger;
import java.util.Arrays;
+import java.util.Objects;
/**
* This immutable class defines an elliptic curve (EC)
@@ -215,6 +216,7 @@ public class ECFieldF2m implements ECField {
* of ECFieldF2m and both {@code m} and the reduction
* polynomial match, false otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) return true;
@@ -226,15 +228,12 @@ public class ECFieldF2m implements ECField {
}
/**
- * Returns a hash code value for this characteristic 2
- * finite field.
- * @return a hash code value.
+ * {@return the hash code value for this characteristic 2 finite field}
*/
+ @Override
public int hashCode() {
- int value = m << 5;
- value += (rp==null? 0:rp.hashCode());
// no need to involve ks here since ks and rp
// should be equivalent.
- return value;
+ return m << 5 + Objects.hashCode(rp);
}
}
diff --git a/src/java.base/share/classes/java/security/spec/ECFieldFp.java b/src/java.base/share/classes/java/security/spec/ECFieldFp.java
index acf00adb6fd..004aab79474 100644
--- a/src/java.base/share/classes/java/security/spec/ECFieldFp.java
+++ b/src/java.base/share/classes/java/security/spec/ECFieldFp.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, 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
@@ -79,6 +79,7 @@ public class ECFieldFp implements ECField {
* @return true if {@code obj} is an instance
* of ECFieldFp and the prime value match, false otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) return true;
@@ -87,9 +88,9 @@ public class ECFieldFp implements ECField {
}
/**
- * Returns a hash code value for this prime finite field.
- * @return a hash code value.
+ * {@return a hash code value for this prime finite field}
*/
+ @Override
public int hashCode() {
return p.hashCode();
}
diff --git a/src/java.base/share/classes/java/security/spec/ECPoint.java b/src/java.base/share/classes/java/security/spec/ECPoint.java
index 86a4264ad6c..82f6cb29a12 100644
--- a/src/java.base/share/classes/java/security/spec/ECPoint.java
+++ b/src/java.base/share/classes/java/security/spec/ECPoint.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, 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
@@ -93,6 +93,7 @@ public class ECPoint {
* @return true if {@code obj} is an instance of
* ECPoint and the affine coordinates match, false otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (this == POINT_INFINITY) return false;
@@ -103,9 +104,9 @@ public class ECPoint {
}
/**
- * Returns a hash code value for this elliptic curve point.
- * @return a hash code value.
+ * {@return the hash code value for this elliptic curve point}
*/
+ @Override
public int hashCode() {
if (this == POINT_INFINITY) return 0;
return x.hashCode() << 5 + y.hashCode();
diff --git a/src/java.base/share/classes/javax/crypto/CryptoAllPermission.java b/src/java.base/share/classes/javax/crypto/CryptoAllPermission.java
index 99829d5907e..c72a504da7e 100644
--- a/src/java.base/share/classes/javax/crypto/CryptoAllPermission.java
+++ b/src/java.base/share/classes/javax/crypto/CryptoAllPermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2023, 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
@@ -76,16 +76,15 @@ final class CryptoAllPermission extends CryptoPermission {
* @return {@code true} if obj is a
* {@code CryptoAllPermission} object.
*/
+ @Override
public boolean equals(Object obj) {
return (obj == INSTANCE);
}
/**
- *
- * Returns the hash code value for this object.
- *
- * @return a hash code value for this object.
+ * {@return the hash code value for this object}
*/
+ @Override
public int hashCode() {
return 1;
}
diff --git a/src/java.base/share/classes/javax/crypto/CryptoPermission.java b/src/java.base/share/classes/javax/crypto/CryptoPermission.java
index d4999aea592..f13eec7a1d9 100644
--- a/src/java.base/share/classes/javax/crypto/CryptoPermission.java
+++ b/src/java.base/share/classes/javax/crypto/CryptoPermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2023, 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
@@ -30,6 +30,7 @@ import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
import java.io.Serializable;
import java.util.Enumeration;
+import java.util.Objects;
import java.util.Vector;
import javax.crypto.spec.*;
@@ -252,6 +253,7 @@ class CryptoPermission extends java.security.Permission {
* @param obj the object to test for equality with this object.
* @return {@code true} if {@code obj} is equal to this object.
*/
+ @Override
public boolean equals(Object obj) {
if (obj == this)
return true;
@@ -266,29 +268,20 @@ class CryptoPermission extends java.security.Permission {
if (this.checkParam != that.checkParam) {
return false;
}
- return (equalObjects(this.exemptionMechanism,
- that.exemptionMechanism) &&
- equalObjects(this.algParamSpec,
- that.algParamSpec));
+ return Objects.equals(this.exemptionMechanism, that.exemptionMechanism)
+ && Objects.equals(this.algParamSpec, that.algParamSpec);
}
/**
- * Returns the hash code value for this object.
- *
- * @return a hash code value for this object.
+ * {@return the hash code value for this object}
*/
-
+ @Override
public int hashCode() {
- int retval = alg.hashCode();
- retval ^= maxKeySize;
- if (exemptionMechanism != null) {
- retval ^= exemptionMechanism.hashCode();
- }
- if (checkParam) retval ^= 100;
- if (algParamSpec != null) {
- retval ^= algParamSpec.hashCode();
- }
- return retval;
+ return alg.hashCode()
+ ^ maxKeySize
+ ^ Objects.hashCode(exemptionMechanism)
+ ^ (checkParam ? 100 : 0)
+ ^ Objects.hashCode(algParamSpec);
}
/**
@@ -437,14 +430,6 @@ class CryptoPermission extends java.security.Permission {
return !this.checkParam;
}
}
-
- private boolean equalObjects(Object obj1, Object obj2) {
- if (obj1 == null) {
- return (obj2 == null);
- }
-
- return obj1.equals(obj2);
- }
}
/**
diff --git a/src/java.base/share/classes/javax/crypto/CryptoPolicyParser.java b/src/java.base/share/classes/javax/crypto/CryptoPolicyParser.java
index ca1415dc8e8..8d580caa050 100644
--- a/src/java.base/share/classes/javax/crypto/CryptoPolicyParser.java
+++ b/src/java.base/share/classes/javax/crypto/CryptoPolicyParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2023, 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
@@ -29,6 +29,7 @@ import java.io.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Objects;
import java.util.Vector;
import static java.util.Locale.ENGLISH;
@@ -616,20 +617,17 @@ final class CryptoPolicyParser {
* Calculates a hash code value for the object. Objects
* which are equal will also have the same hashcode.
*/
+ @Override
public int hashCode() {
- int retval = cryptoPermission.hashCode();
- if (alg != null) retval ^= alg.hashCode();
- if (exemptionMechanism != null) {
- retval ^= exemptionMechanism.hashCode();
- }
- retval ^= maxKeySize;
- if (checkParam) retval ^= 100;
- if (algParamSpec != null) {
- retval ^= algParamSpec.hashCode();
- }
- return retval;
+ return cryptoPermission.hashCode()
+ ^ Objects.hashCode(alg)
+ ^ Objects.hashCode(exemptionMechanism)
+ ^ maxKeySize
+ ^ (checkParam ? 100 : 0)
+ ^ Objects.hashCode(algParamSpec);
}
+ @Override
public boolean equals(Object obj) {
if (obj == this)
return true;
@@ -637,12 +635,8 @@ final class CryptoPolicyParser {
if (!(obj instanceof CryptoPermissionEntry that))
return false;
- if (this.cryptoPermission == null) {
- if (that.cryptoPermission != null) return false;
- } else {
- if (!this.cryptoPermission.equals(
- that.cryptoPermission))
- return false;
+ if (!Objects.equals(this.cryptoPermission, that.cryptoPermission)) {
+ return false;
}
if (this.alg == null) {
@@ -652,15 +646,11 @@ final class CryptoPolicyParser {
return false;
}
- if (!(this.maxKeySize == that.maxKeySize)) return false;
+ if (this.maxKeySize != that.maxKeySize) return false;
if (this.checkParam != that.checkParam) return false;
- if (this.algParamSpec == null) {
- return that.algParamSpec == null;
- } else {
- return this.algParamSpec.equals(that.algParamSpec);
- }
+ return Objects.equals(this.algParamSpec, that.algParamSpec);
}
}
diff --git a/src/java.base/share/classes/javax/crypto/spec/RC2ParameterSpec.java b/src/java.base/share/classes/javax/crypto/spec/RC2ParameterSpec.java
index 16812dcc389..6c32ee119c5 100644
--- a/src/java.base/share/classes/javax/crypto/spec/RC2ParameterSpec.java
+++ b/src/java.base/share/classes/javax/crypto/spec/RC2ParameterSpec.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2023, 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
@@ -26,6 +26,7 @@
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
+import java.util.Arrays;
/**
* This class specifies the parameters used with the
@@ -131,6 +132,7 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec {
* @return true if the objects are considered equal, false if
* {@code obj} is null or otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
@@ -140,20 +142,15 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec {
}
return ((effectiveKeyBits == other.effectiveKeyBits) &&
- java.util.Arrays.equals(iv, other.iv));
+ Arrays.equals(iv, other.iv));
}
/**
* Calculates a hash code value for the object.
* Objects that are equal will also have the same hashcode.
*/
+ @Override
public int hashCode() {
- int retval = 0;
- if (iv != null) {
- for (int i = 1; i < iv.length; i++) {
- retval += iv[i] * i;
- }
- }
- return retval + effectiveKeyBits;
+ return Arrays.hashCode(iv) + effectiveKeyBits;
}
}
diff --git a/src/java.base/share/classes/javax/crypto/spec/RC5ParameterSpec.java b/src/java.base/share/classes/javax/crypto/spec/RC5ParameterSpec.java
index 4bee63d9932..7e4aab20e68 100644
--- a/src/java.base/share/classes/javax/crypto/spec/RC5ParameterSpec.java
+++ b/src/java.base/share/classes/javax/crypto/spec/RC5ParameterSpec.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2023, 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
@@ -26,6 +26,7 @@
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
+import java.util.Arrays;
/**
* This class specifies the parameters used with the
@@ -176,6 +177,7 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
* @return true if the objects are considered equal, false if
* {@code obj} is null or otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
@@ -187,21 +189,15 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
return ((version == other.version) &&
(rounds == other.rounds) &&
(wordSize == other.wordSize) &&
- java.util.Arrays.equals(iv, other.iv));
+ Arrays.equals(iv, other.iv));
}
/**
* Calculates a hash code value for the object.
* Objects that are equal will also have the same hashcode.
*/
+ @Override
public int hashCode() {
- int retval = 0;
- if (iv != null) {
- for (int i = 1; i < iv.length; i++) {
- retval += iv[i] * i;
- }
- }
- retval += (version + rounds + wordSize);
- return retval;
+ return Arrays.hashCode(iv) + version + rounds + wordSize;
}
}
diff --git a/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java b/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java
index 5517d88157d..d1326f89175 100644
--- a/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java
+++ b/src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2023, 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
@@ -198,11 +198,9 @@ public class SecretKeySpec implements KeySpec, SecretKey {
* Calculates a hash code value for the object.
* Objects that are equal will also have the same hashcode.
*/
+ @Override
public int hashCode() {
- int retval = 0;
- for (int i = 1; i < this.key.length; i++) {
- retval += this.key[i] * i;
- }
+ int retval = Arrays.hashCode(key);
if (this.algorithm.equalsIgnoreCase("TripleDES"))
return retval ^ "desede".hashCode();
else
@@ -220,14 +218,15 @@ public class SecretKeySpec implements KeySpec, SecretKey {
* @return true if the objects are considered equal, false if
* obj is null or otherwise.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
- if (!(obj instanceof SecretKey))
+ if (!(obj instanceof SecretKey that))
return false;
- String thatAlg = ((SecretKey)obj).getAlgorithm();
+ String thatAlg = that.getAlgorithm();
if (!(thatAlg.equalsIgnoreCase(this.algorithm))) {
if ((!(thatAlg.equalsIgnoreCase("DESede"))
|| !(this.algorithm.equalsIgnoreCase("TripleDES")))
@@ -236,7 +235,7 @@ public class SecretKeySpec implements KeySpec, SecretKey {
return false;
}
- byte[] thatKey = ((SecretKey)obj).getEncoded();
+ byte[] thatKey = that.getEncoded();
try {
return MessageDigest.isEqual(this.key, thatKey);
} finally {
diff --git a/src/java.base/share/classes/javax/security/auth/PrivateCredentialPermission.java b/src/java.base/share/classes/javax/security/auth/PrivateCredentialPermission.java
index 8b7df9dccc3..1857caeb799 100644
--- a/src/java.base/share/classes/javax/security/auth/PrivateCredentialPermission.java
+++ b/src/java.base/share/classes/javax/security/auth/PrivateCredentialPermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2023, 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
@@ -260,6 +260,7 @@ public final class PrivateCredentialPermission extends Permission {
* has the same credential class as this object,
* and has the same Principals as this object.
*/
+ @Override
public boolean equals(Object obj) {
if (obj == this)
return true;
@@ -271,10 +272,9 @@ public final class PrivateCredentialPermission extends Permission {
}
/**
- * Returns the hash code value for this object.
- *
- * @return a hash code value for this object.
+ * {@return the hash code value for this object}
*/
+ @Override
public int hashCode() {
return this.credentialClass.hashCode();
}
diff --git a/src/java.base/share/classes/javax/security/auth/Subject.java b/src/java.base/share/classes/javax/security/auth/Subject.java
index 9d304a1da44..60e6d5fe30e 100644
--- a/src/java.base/share/classes/javax/security/auth/Subject.java
+++ b/src/java.base/share/classes/javax/security/auth/Subject.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2023, 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
@@ -907,10 +907,6 @@ public final class Subject implements java.io.Serializable {
@Override
public boolean equals(Object o) {
- if (o == null) {
- return false;
- }
-
if (this == o) {
return true;
}
@@ -1003,9 +999,7 @@ public final class Subject implements java.io.Serializable {
}
/**
- * Returns a hashcode for this {@code Subject}.
- *
- * @return a hashcode for this {@code Subject}.
+ * {@return a hashcode for this {@code Subject}}
*
* @throws SecurityException if a security manager is installed and the
* caller does not have a {@link PrivateCredentialPermission}
@@ -1486,6 +1480,7 @@ public final class Subject implements java.io.Serializable {
return elements.toArray(a);
}
+ @Override
public boolean equals(Object o) {
if (o == this) {
return true;
@@ -1507,14 +1502,11 @@ public final class Subject implements java.io.Serializable {
}
}
+ @Override
public int hashCode() {
int h = 0;
- Iterator i = iterator();
- while (i.hasNext()) {
- E obj = i.next();
- if (obj != null) {
- h += obj.hashCode();
- }
+ for (E obj : this) {
+ h += Objects.hashCode(obj);
}
return h;
}
diff --git a/src/java.base/share/classes/javax/security/auth/x500/X500Principal.java b/src/java.base/share/classes/javax/security/auth/x500/X500Principal.java
index e2c8795a2e2..f58a37f0997 100644
--- a/src/java.base/share/classes/javax/security/auth/x500/X500Principal.java
+++ b/src/java.base/share/classes/javax/security/auth/x500/X500Principal.java
@@ -457,6 +457,7 @@ public final class X500Principal implements Principal, java.io.Serializable {
* @return {@code true} if the specified {@code Object} is equal
* to this {@code X500Principal}, {@code false} otherwise
*/
+ @Override
public boolean equals(Object o) {
if (this == o) {
return true;
@@ -468,13 +469,12 @@ public final class X500Principal implements Principal, java.io.Serializable {
}
/**
- * Return a hash code for this {@code X500Principal}.
+ * {@return a hash code for this {@code X500Principal}}
*
* The hash code is calculated via:
* {@code getName(X500Principal.CANONICAL).hashCode()}
- *
- * @return a hash code for this {@code X500Principal}
*/
+ @Override
public int hashCode() {
return thisX500Name.hashCode();
}
diff --git a/src/java.base/share/classes/javax/security/cert/Certificate.java b/src/java.base/share/classes/javax/security/cert/Certificate.java
index 602d6b7fd2b..b06994147ae 100644
--- a/src/java.base/share/classes/javax/security/cert/Certificate.java
+++ b/src/java.base/share/classes/javax/security/cert/Certificate.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -31,6 +31,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.InvalidKeyException;
import java.security.SignatureException;
+import java.util.Arrays;
/**
*
Abstract class for managing a variety of identity certificates.
@@ -72,51 +73,38 @@ public abstract class Certificate {
/**
* Compares this certificate for equality with the specified
- * object. If the {@code other} object is an
+ * object. If the {@code obj} object is an
* {@code instanceof} {@code Certificate}, then
* its encoded form is retrieved and compared with the
* encoded form of this certificate.
*
- * @param other the object to test for equality with this certificate.
+ * @param obj the object to test for equality with this certificate.
* @return true if the encoded forms of the two certificates
* match, false otherwise.
*/
- public boolean equals(Object other) {
- if (this == other)
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
return true;
- if (!(other instanceof Certificate))
+ if (!(obj instanceof Certificate other))
return false;
try {
- byte[] thisCert = this.getEncoded();
- byte[] otherCert = ((Certificate)other).getEncoded();
-
- if (thisCert.length != otherCert.length)
- return false;
- for (int i = 0; i < thisCert.length; i++)
- if (thisCert[i] != otherCert[i])
- return false;
- return true;
+ return Arrays.equals(this.getEncoded(), other.getEncoded());
} catch (CertificateException e) {
return false;
}
}
/**
- * Returns a hashcode value for this certificate from its
- * encoded form.
- *
- * @return the hashcode value.
+ * {@return a hashcode value for this certificate from
+ * its encoded form}
*/
+ @Override
public int hashCode() {
- int retval = 0;
try {
- byte[] certData = this.getEncoded();
- for (int i = 1; i < certData.length; i++) {
- retval += certData[i] * i;
- }
- return (retval);
+ return Arrays.hashCode(this.getEncoded());
} catch (CertificateException e) {
- return (retval);
+ return 0;
}
}
diff --git a/src/java.base/share/classes/sun/security/jca/ProviderConfig.java b/src/java.base/share/classes/sun/security/jca/ProviderConfig.java
index 90106674b9d..ace87630dac 100644
--- a/src/java.base/share/classes/sun/security/jca/ProviderConfig.java
+++ b/src/java.base/share/classes/sun/security/jca/ProviderConfig.java
@@ -132,6 +132,7 @@ final class ProviderConfig {
return (provider != null);
}
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -144,8 +145,9 @@ final class ProviderConfig {
}
+ @Override
public int hashCode() {
- return provName.hashCode() + argument.hashCode();
+ return Objects.hash(provName, argument);
}
public String toString() {
diff --git a/src/java.base/share/classes/sun/security/pkcs/EncryptedPrivateKeyInfo.java b/src/java.base/share/classes/sun/security/pkcs/EncryptedPrivateKeyInfo.java
index df9f4097df0..05809108398 100644
--- a/src/java.base/share/classes/sun/security/pkcs/EncryptedPrivateKeyInfo.java
+++ b/src/java.base/share/classes/sun/security/pkcs/EncryptedPrivateKeyInfo.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2023, 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
@@ -26,6 +26,8 @@
package sun.security.pkcs;
import java.io.*;
+import java.util.Arrays;
+
import sun.security.x509.*;
import sun.security.util.DerValue;
import sun.security.util.DerOutputStream;
@@ -134,33 +136,20 @@ public class EncryptedPrivateKeyInfo {
return this.encoded.clone();
}
- public boolean equals(Object other) {
- if (this == other)
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
return true;
- if (!(other instanceof EncryptedPrivateKeyInfo))
- return false;
- byte[] thisEncrInfo = this.getEncoded();
- byte[] otherEncrInfo
- = ((EncryptedPrivateKeyInfo) other).getEncoded();
-
- if (thisEncrInfo.length != otherEncrInfo.length)
- return false;
- for (int i = 0; i < thisEncrInfo.length; i++)
- if (thisEncrInfo[i] != otherEncrInfo[i])
- return false;
- return true;
+ }
+ return obj instanceof EncryptedPrivateKeyInfo other
+ && Arrays.equals(this.getEncoded(), other.getEncoded());
}
/**
- * Returns a hashcode for this EncryptedPrivateKeyInfo.
- *
- * @return a hashcode for this EncryptedPrivateKeyInfo.
+ * {@return a hashcode for this EncryptedPrivateKeyInfo}
*/
+ @Override
public int hashCode() {
- int retval = 0;
-
- for (int i = 0; i < this.encryptedData.length; i++)
- retval += this.encryptedData[i] * i;
- return retval;
+ return Arrays.hashCode(encryptedData);
}
}
diff --git a/src/java.base/share/classes/sun/security/pkcs/PKCS8Key.java b/src/java.base/share/classes/sun/security/pkcs/PKCS8Key.java
index a62ed650eb3..4cb277b43a8 100644
--- a/src/java.base/share/classes/sun/security/pkcs/PKCS8Key.java
+++ b/src/java.base/share/classes/sun/security/pkcs/PKCS8Key.java
@@ -259,6 +259,7 @@ public class PKCS8Key implements PrivateKey, InternalPrivateKey {
* @return {@code true} if this key has the same encoding as the
* object argument; {@code false} otherwise.
*/
+ @Override
public boolean equals(Object object) {
if (this == object) {
return true;
@@ -288,6 +289,7 @@ public class PKCS8Key implements PrivateKey, InternalPrivateKey {
* Calculates a hash code value for this object. Objects
* which are equal will also have the same hashcode.
*/
+ @Override
public int hashCode() {
return Arrays.hashCode(getEncodedInternal());
}
diff --git a/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java b/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java
index af1cc7b7752..943af4d2333 100644
--- a/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java
+++ b/src/java.base/share/classes/sun/security/pkcs10/PKCS10.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2023, 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
@@ -32,6 +32,7 @@ import java.math.BigInteger;
import java.security.*;
+import java.util.Arrays;
import java.util.Base64;
import sun.security.util.*;
@@ -324,41 +325,37 @@ public class PKCS10 {
/**
* Compares this object for equality with the specified
- * object. If the other object is an
+ * object. If the obj object is an
* instanceof PKCS10, then
* its encoded form is retrieved and compared with the
* encoded form of this certificate request.
*
- * @param other the object to test for equality with this object.
+ * @param obj the object to test for equality with this object.
* @return true iff the encoded forms of the two certificate
* requests match, false otherwise.
*/
- public boolean equals(Object other) {
- if (this == other)
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
return true;
- if (!(other instanceof PKCS10))
+ if (!(obj instanceof PKCS10 other))
return false;
if (encoded == null) // not signed yet
return false;
- byte[] otherEncoded = ((PKCS10)other).getEncoded();
+ byte[] otherEncoded = other.getEncoded();
if (otherEncoded == null)
return false;
- return java.util.Arrays.equals(encoded, otherEncoded);
+ return Arrays.equals(encoded, otherEncoded);
}
/**
- * Returns a hashcode value for this certificate request from its
- * encoded form.
- *
- * @return the hashcode value.
+ * {@return the hashcode value for this certificate request from its
+ * encoded form}
*/
+ @Override
public int hashCode() {
- int retval = 0;
- if (encoded != null)
- for (int i = 1; i < encoded.length; i++)
- retval += encoded[i] * i;
- return(retval);
+ return Arrays.hashCode(encoded);
}
private X500Name subject;
diff --git a/src/java.base/share/classes/sun/security/pkcs10/PKCS10Attributes.java b/src/java.base/share/classes/sun/security/pkcs10/PKCS10Attributes.java
index 979c5eea00c..1fb506fb58a 100644
--- a/src/java.base/share/classes/sun/security/pkcs10/PKCS10Attributes.java
+++ b/src/java.base/share/classes/sun/security/pkcs10/PKCS10Attributes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -153,6 +153,7 @@ public class PKCS10Attributes implements DerEncoder {
* @return true if all the entries match that of the Other,
* false otherwise.
*/
+ @Override
public boolean equals(Object other) {
if (this == other)
return true;
@@ -166,26 +167,24 @@ public class PKCS10Attributes implements DerEncoder {
int len = attrs.length;
if (len != map.size())
return false;
- PKCS10Attribute thisAttr, otherAttr;
+ PKCS10Attribute thisAttr;
String key;
- for (int i=0; i < len; i++) {
- otherAttr = attrs[i];
+ for (PKCS10Attribute otherAttr : attrs) {
key = otherAttr.getAttributeId().toString();
thisAttr = map.get(key);
if (thisAttr == null)
return false;
- if (! thisAttr.equals(otherAttr))
+ if (!thisAttr.equals(otherAttr))
return false;
}
return true;
}
/**
- * Returns a hashcode value for this PKCS10Attributes.
- *
- * @return the hashcode value.
+ * {@return the hashcode value for this PKCS10Attributes}
*/
+ @Override
public int hashCode() {
return map.hashCode();
}
diff --git a/src/java.base/share/classes/sun/security/provider/PolicyFile.java b/src/java.base/share/classes/sun/security/provider/PolicyFile.java
index f69f513dc9f..2a5c13b8bc2 100644
--- a/src/java.base/share/classes/sun/security/provider/PolicyFile.java
+++ b/src/java.base/share/classes/sun/security/provider/PolicyFile.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -2129,17 +2129,11 @@ public class PolicyFile extends java.security.Policy {
}
/**
- * Returns the hash code value for this object.
- *
- * @return a hash code value for this object.
+ * {@return the hash code value for this object}
*/
@Override public int hashCode() {
- int hash = type.hashCode();
- if (name != null)
- hash ^= name.hashCode();
- if (actions != null)
- hash ^= actions.hashCode();
- return hash;
+ return type.hashCode() ^ Objects.hashCode(name)
+ ^ Objects.hashCode(actions);
}
/**
diff --git a/src/java.base/share/classes/sun/security/provider/PolicyParser.java b/src/java.base/share/classes/sun/security/provider/PolicyParser.java
index 257bc9124f9..2789d37c7a7 100644
--- a/src/java.base/share/classes/sun/security/provider/PolicyParser.java
+++ b/src/java.base/share/classes/sun/security/provider/PolicyParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -1058,9 +1058,7 @@ public class PolicyParser {
}
/**
- * Return a hashcode for this PrincipalEntry.
- *
- * @return a hashcode for this PrincipalEntry
+ * {@return a hashcode for this PrincipalEntry}
*/
@Override
public int hashCode() {
@@ -1119,10 +1117,7 @@ public class PolicyParser {
*/
@Override
public int hashCode() {
- int retval = permission.hashCode();
- if (name != null) retval ^= name.hashCode();
- if (action != null) retval ^= action.hashCode();
- return retval;
+ return Objects.hash(permission, name, action);
}
@Override
@@ -1130,32 +1125,11 @@ public class PolicyParser {
if (obj == this)
return true;
- if (! (obj instanceof PermissionEntry that))
- return false;
-
- if (this.permission == null) {
- if (that.permission != null) return false;
- } else {
- if (!this.permission.equals(that.permission)) return false;
- }
-
- if (this.name == null) {
- if (that.name != null) return false;
- } else {
- if (!this.name.equals(that.name)) return false;
- }
-
- if (this.action == null) {
- if (that.action != null) return false;
- } else {
- if (!this.action.equals(that.action)) return false;
- }
-
- if (this.signedBy == null) {
- return that.signedBy == null;
- } else {
- return this.signedBy.equals(that.signedBy);
- }
+ return obj instanceof PermissionEntry that
+ && Objects.equals(this.permission, that.permission)
+ && Objects.equals(this.name, that.name)
+ && Objects.equals(this.action, that.action)
+ && Objects.equals(this.signedBy, that.signedBy);
}
public void write(PrintWriter out) {
diff --git a/src/java.base/share/classes/sun/security/provider/certpath/CertId.java b/src/java.base/share/classes/sun/security/provider/certpath/CertId.java
index c3f6d39ba36..9b5a5d7ac64 100644
--- a/src/java.base/share/classes/sun/security/provider/certpath/CertId.java
+++ b/src/java.base/share/classes/sun/security/provider/certpath/CertId.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, 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
@@ -172,19 +172,13 @@ public class CertId implements DerEncoder {
}
/**
- * Returns a hashcode value for this CertId.
- *
- * @return the hashcode value.
+ * {@return a hashcode value for this CertId}
*/
@Override public int hashCode() {
if (myhash == -1) {
myhash = hashAlgId.hashCode();
- for (int i = 0; i < issuerNameHash.length; i++) {
- myhash += issuerNameHash[i] * i;
- }
- for (int i = 0; i < issuerKeyHash.length; i++) {
- myhash += issuerKeyHash[i] * i;
- }
+ myhash += Arrays.hashCode(issuerNameHash);
+ myhash += Arrays.hashCode(issuerKeyHash);
myhash += certSerialNumber.getNumber().hashCode();
}
return myhash;
diff --git a/src/java.base/share/classes/sun/security/provider/certpath/ResponderId.java b/src/java.base/share/classes/sun/security/provider/certpath/ResponderId.java
index 09c9dc7d3c9..f4d00b394a0 100644
--- a/src/java.base/share/classes/sun/security/provider/certpath/ResponderId.java
+++ b/src/java.base/share/classes/sun/security/provider/certpath/ResponderId.java
@@ -226,25 +226,16 @@ public final class ResponderId {
*/
@Override
public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
-
if (this == obj) {
return true;
}
- if (obj instanceof ResponderId respObj) {
- return Arrays.equals(encodedRid, respObj.getEncoded());
- }
-
- return false;
+ return obj instanceof ResponderId respObj
+ && Arrays.equals(encodedRid, respObj.getEncoded());
}
/**
- * Returns the hash code value for this {@code ResponderId}
- *
- * @return the hash code value for this {@code ResponderId}
+ * {@return the hash code value for this {@code ResponderId}}
*/
@Override
public int hashCode() {
diff --git a/src/java.base/share/classes/sun/security/ssl/SSLSessionImpl.java b/src/java.base/share/classes/sun/security/ssl/SSLSessionImpl.java
index 3f1aa08241b..a0708618e15 100644
--- a/src/java.base/share/classes/sun/security/ssl/SSLSessionImpl.java
+++ b/src/java.base/share/classes/sun/security/ssl/SSLSessionImpl.java
@@ -985,7 +985,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
}
/**
- * Returns the hashcode for this session
+ * {@return the hashcode for this session}
*/
@Override
public int hashCode() {
@@ -1002,12 +1002,9 @@ final class SSLSessionImpl extends ExtendedSSLSession {
return true;
}
- if (obj instanceof SSLSessionImpl sess) {
- return (sessionId != null) && (sessionId.equals(
- sess.getSessionId()));
- }
-
- return false;
+ return obj instanceof SSLSessionImpl other
+ && sessionId != null
+ && sessionId.equals(other.getSessionId());
}
diff --git a/src/java.base/share/classes/sun/security/tools/keytool/Main.java b/src/java.base/share/classes/sun/security/tools/keytool/Main.java
index edb0b41950a..2effa3425d7 100644
--- a/src/java.base/share/classes/sun/security/tools/keytool/Main.java
+++ b/src/java.base/share/classes/sun/security/tools/keytool/Main.java
@@ -5315,13 +5315,15 @@ class Pair {
return "Pair[" + fst + "," + snd + "]";
}
- public boolean equals(Object other) {
+ @Override
+ public boolean equals(Object obj) {
return
- other instanceof Pair &&
- Objects.equals(fst, ((Pair)other).fst) &&
- Objects.equals(snd, ((Pair)other).snd);
+ obj instanceof Pair, ?> other &&
+ Objects.equals(fst, other.fst) &&
+ Objects.equals(snd, other.snd);
}
+ @Override
public int hashCode() {
if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1;
else if (snd == null) return fst.hashCode() + 2;
diff --git a/src/java.base/share/classes/sun/security/util/BitArray.java b/src/java.base/share/classes/sun/security/util/BitArray.java
index adf16769e89..44bf7084b7f 100644
--- a/src/java.base/share/classes/sun/security/util/BitArray.java
+++ b/src/java.base/share/classes/sun/security/util/BitArray.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -26,6 +26,7 @@
package sun.security.util;
import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
import jdk.internal.util.Preconditions;
@@ -68,7 +69,7 @@ public class BitArray {
* Creates a BitArray of the specified size, initialized from the
* specified byte array. The most significant bit of {@code a[0]} gets
* index zero in the BitArray. The array must be large enough to specify
- * a value for every bit of the BitArray. i.e. {@code 8*a.length <= length}.
+ * a value for every bit of the BitArray, i.e. {@code 8*a.length >= length}.
*/
public BitArray(int length, byte[] a) throws IllegalArgumentException {
this(length, a, 0);
@@ -79,7 +80,7 @@ public class BitArray {
* specified byte array starting at the specified offset. The most
* significant bit of {@code a[ofs]} gets index zero in the BitArray.
* The array must be large enough to specify a value for every bit of
- * the BitArray, i.e. {@code 8*(a.length - ofs) <= length}.
+ * the BitArray, i.e. {@code 8*(a.length - ofs) >= length}.
*/
public BitArray(int length, byte[] a, int ofs)
throws IllegalArgumentException {
@@ -177,16 +178,13 @@ public class BitArray {
return repn.clone();
}
+ @Override
public boolean equals(Object obj) {
if (obj == this) return true;
- if (!(obj instanceof BitArray ba)) return false;
- if (ba.length != length) return false;
-
- for (int i = 0; i < repn.length; i += 1) {
- if (repn[i] != ba.repn[i]) return false;
- }
- return true;
+ return obj instanceof BitArray other
+ && length == other.length
+ && Arrays.equals(repn, other.repn);
}
/**
@@ -202,17 +200,11 @@ public class BitArray {
}
/**
- * Returns a hash code value for this bit array.
- *
- * @return a hash code value for this bit array.
+ * {@return a hash code value for this bit array}
*/
+ @Override
public int hashCode() {
- int hashCode = 0;
-
- for (int i = 0; i < repn.length; i++)
- hashCode = 31*hashCode + repn[i];
-
- return hashCode ^ length;
+ return Arrays.hashCode(repn) ^ length;
}
diff --git a/src/java.base/share/classes/sun/security/util/DerValue.java b/src/java.base/share/classes/sun/security/util/DerValue.java
index 3b054ea0a37..4ce0e553382 100644
--- a/src/java.base/share/classes/sun/security/util/DerValue.java
+++ b/src/java.base/share/classes/sun/security/util/DerValue.java
@@ -1261,9 +1261,7 @@ public class DerValue {
}
/**
- * Returns a hashcode for this DerValue.
- *
- * @return a hashcode for this DerValue.
+ * {@return a hashcode for this DerValue}
*/
@Override
public int hashCode() {
diff --git a/src/java.base/share/classes/sun/security/x509/AVA.java b/src/java.base/share/classes/sun/security/x509/AVA.java
index 236c78669e3..b1143600d6b 100644
--- a/src/java.base/share/classes/sun/security/x509/AVA.java
+++ b/src/java.base/share/classes/sun/security/x509/AVA.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2023, 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
@@ -596,6 +596,7 @@ public class AVA implements DerEncoder {
this(in.getDerValue());
}
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -608,10 +609,9 @@ public class AVA implements DerEncoder {
}
/**
- * Returns a hashcode for this AVA.
- *
- * @return a hashcode for this AVA.
+ * {@return a hashcode for this AVA}
*/
+ @Override
public int hashCode() {
return toRFC2253CanonicalString().hashCode();
}
diff --git a/src/java.base/share/classes/sun/security/x509/AlgorithmId.java b/src/java.base/share/classes/sun/security/x509/AlgorithmId.java
index 1f8dbe368bd..4edb5d9ae4d 100644
--- a/src/java.base/share/classes/sun/security/x509/AlgorithmId.java
+++ b/src/java.base/share/classes/sun/security/x509/AlgorithmId.java
@@ -339,9 +339,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
}
/**
- * Returns a hashcode for this AlgorithmId.
- *
- * @return a hashcode for this AlgorithmId.
+ * {@return a hashcode for this AlgorithmId}
*/
@Override
public int hashCode() {
diff --git a/src/java.base/share/classes/sun/security/x509/CRLExtensions.java b/src/java.base/share/classes/sun/security/x509/CRLExtensions.java
index 17f9aa220a3..214b043033a 100644
--- a/src/java.base/share/classes/sun/security/x509/CRLExtensions.java
+++ b/src/java.base/share/classes/sun/security/x509/CRLExtensions.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -218,6 +218,7 @@ public class CRLExtensions {
* @return true iff all the entries match that of the Other,
* false otherwise.
*/
+ @Override
public boolean equals(Object other) {
if (this == other)
return true;
@@ -242,10 +243,9 @@ public class CRLExtensions {
}
/**
- * Returns a hashcode value for this CRLExtensions.
- *
- * @return the hashcode value.
+ * {@return a hashcode value for this CRLExtensions}
*/
+ @Override
public int hashCode() {
return map.hashCode();
}
diff --git a/src/java.base/share/classes/sun/security/x509/CertificateExtensions.java b/src/java.base/share/classes/sun/security/x509/CertificateExtensions.java
index ff26880680e..13a7acb6cf7 100644
--- a/src/java.base/share/classes/sun/security/x509/CertificateExtensions.java
+++ b/src/java.base/share/classes/sun/security/x509/CertificateExtensions.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -247,6 +247,7 @@ public class CertificateExtensions implements DerEncoder {
* @return true iff all the entries match that of the Other,
* false otherwise.
*/
+ @Override
public boolean equals(Object other) {
if (this == other)
return true;
@@ -272,12 +273,11 @@ public class CertificateExtensions implements DerEncoder {
}
/**
- * Returns a hashcode value for this CertificateExtensions.
- *
- * @return the hashcode value.
+ * {@return a hashcode value for this CertificateExtensions}
*/
+ @Override
public int hashCode() {
- return map.hashCode() + getUnparseableExtensions().hashCode();
+ return Objects.hash(map, getUnparseableExtensions());
}
/**
diff --git a/src/java.base/share/classes/sun/security/x509/CertificatePolicyId.java b/src/java.base/share/classes/sun/security/x509/CertificatePolicyId.java
index b1bfbfabe0f..0d2b8662c30 100644
--- a/src/java.base/share/classes/sun/security/x509/CertificatePolicyId.java
+++ b/src/java.base/share/classes/sun/security/x509/CertificatePolicyId.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -92,18 +92,16 @@ public class CertificatePolicyId implements DerEncoder {
*
* @return true iff the ids are identical.
*/
- public boolean equals(Object other) {
- if (other instanceof CertificatePolicyId)
- return id.equals(((CertificatePolicyId) other).getIdentifier());
- else
- return false;
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof CertificatePolicyId other
+ && id.equals(other.getIdentifier());
}
/**
- * Returns a hash code value for this object.
- *
- * @return a hash code value
+ * {@return a hash code value for this object}
*/
+ @Override
public int hashCode() {
return id.hashCode();
}
diff --git a/src/java.base/share/classes/sun/security/x509/DNSName.java b/src/java.base/share/classes/sun/security/x509/DNSName.java
index 647a029413d..25443724f5a 100644
--- a/src/java.base/share/classes/sun/security/x509/DNSName.java
+++ b/src/java.base/share/classes/sun/security/x509/DNSName.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -169,6 +169,7 @@ public class DNSName implements GeneralNameInterface {
* @return true iff the names are equivalent
* according to RFC5280.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
@@ -182,10 +183,9 @@ public class DNSName implements GeneralNameInterface {
}
/**
- * Returns the hash code value for this object.
- *
- * @return a hash code value for this object.
+ * {@return the hash code value for this object}
*/
+ @Override
public int hashCode() {
return name.toUpperCase(Locale.ENGLISH).hashCode();
}
diff --git a/src/java.base/share/classes/sun/security/x509/DistributionPoint.java b/src/java.base/share/classes/sun/security/x509/DistributionPoint.java
index a31e93e2e44..3c120a2563c 100644
--- a/src/java.base/share/classes/sun/security/x509/DistributionPoint.java
+++ b/src/java.base/share/classes/sun/security/x509/DistributionPoint.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2023, 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
@@ -325,6 +325,7 @@ public class DistributionPoint implements DerEncoder {
* @param obj Object to be compared to this
* @return true if objects match; false otherwise
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -339,26 +340,14 @@ public class DistributionPoint implements DerEncoder {
&& Arrays.equals(this.reasonFlags, other.reasonFlags);
}
+ @Override
public int hashCode() {
int hash = hashCode;
if (hash == 0) {
- hash = 1;
- if (fullName != null) {
- hash += fullName.hashCode();
- }
- if (relativeName != null) {
- hash += relativeName.hashCode();
- }
- if (crlIssuer != null) {
- hash += crlIssuer.hashCode();
- }
- if (reasonFlags != null) {
- for (int i = 0; i < reasonFlags.length; i++) {
- if (reasonFlags[i]) {
- hash += i;
- }
- }
- }
+ hash = 1 + Objects.hashCode(fullName)
+ + Objects.hashCode(relativeName)
+ + Objects.hash(crlIssuer)
+ + Arrays.hashCode(reasonFlags);
hashCode = hash;
}
return hash;
diff --git a/src/java.base/share/classes/sun/security/x509/DistributionPointName.java b/src/java.base/share/classes/sun/security/x509/DistributionPointName.java
index d4843fb6c29..c90f390c4d9 100644
--- a/src/java.base/share/classes/sun/security/x509/DistributionPointName.java
+++ b/src/java.base/share/classes/sun/security/x509/DistributionPointName.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2023, 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
@@ -192,6 +192,7 @@ public class DistributionPointName implements DerEncoder {
* @param obj Object to be compared to this
* @return true if objects match; false otherwise
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -205,17 +206,15 @@ public class DistributionPointName implements DerEncoder {
}
/**
- * Returns the hash code for this distribution point name.
- *
- * @return the hash code.
+ * {@return the hash code for this distribution point name}
*/
+ @Override
public int hashCode() {
int hash = hashCode;
if (hash == 0) {
hash = 1;
if (fullName != null) {
hash += fullName.hashCode();
-
} else {
hash += relativeName.hashCode();
}
diff --git a/src/java.base/share/classes/sun/security/x509/EDIPartyName.java b/src/java.base/share/classes/sun/security/x509/EDIPartyName.java
index 4c2362773de..1879a462a51 100644
--- a/src/java.base/share/classes/sun/security/x509/EDIPartyName.java
+++ b/src/java.base/share/classes/sun/security/x509/EDIPartyName.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -170,30 +170,20 @@ public class EDIPartyName implements GeneralNameInterface {
*
* @return true if the two names match
*/
- public boolean equals(Object other) {
- if (!(other instanceof EDIPartyName))
- return false;
- String otherAssigner = ((EDIPartyName)other).assigner;
- if (this.assigner == null) {
- if (otherAssigner != null)
- return false;
- } else {
- if (!(this.assigner.equals(otherAssigner)))
- return false;
- }
- String otherParty = ((EDIPartyName)other).party;
- if (this.party == null) {
- return otherParty == null;
- } else {
- return this.party.equals(otherParty);
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+
+ return obj instanceof EDIPartyName other
+ && Objects.equals(this.assigner, other.assigner)
+ && Objects.equals(this.party, other.party);
}
/**
- * Returns the hash code value for this EDIPartyName.
- *
- * @return a hash code value.
+ * {@return the hash code value for this EDIPartyName}
*/
+ @Override
public int hashCode() {
if (myhash == -1) {
myhash = 37 + (party == null ? 1 : party.hashCode());
diff --git a/src/java.base/share/classes/sun/security/x509/Extension.java b/src/java.base/share/classes/sun/security/x509/Extension.java
index 05c638753d2..4549aabce29 100644
--- a/src/java.base/share/classes/sun/security/x509/Extension.java
+++ b/src/java.base/share/classes/sun/security/x509/Extension.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -242,20 +242,13 @@ public class Extension implements java.security.cert.Extension, DerEncoder {
private static final int hashMagic = 31;
/**
- * Returns a hashcode value for this Extension.
- *
- * @return the hashcode value.
+ * {@return a hashcode value for this Extension}
*/
+ @Override
public int hashCode() {
- int h = 0;
- if (extensionValue != null) {
- byte[] val = extensionValue;
- int len = val.length;
- while (len > 0)
- h += len * val[--len];
- }
+ int h = Arrays.hashCode(extensionValue);
h = h * hashMagic + extensionId.hashCode();
- h = h * hashMagic + (critical?1231:1237);
+ h = h * hashMagic + Boolean.hashCode(critical);
return h;
}
@@ -271,6 +264,7 @@ public class Extension implements java.security.cert.Extension, DerEncoder {
* criticality flag, object identifier and encoded extension value of
* the two Extensions match, false otherwise.
*/
+ @Override
public boolean equals(Object other) {
if (this == other)
return true;
diff --git a/src/java.base/share/classes/sun/security/x509/GeneralName.java b/src/java.base/share/classes/sun/security/x509/GeneralName.java
index 934eee5a558..84dd2359cc4 100644
--- a/src/java.base/share/classes/sun/security/x509/GeneralName.java
+++ b/src/java.base/share/classes/sun/security/x509/GeneralName.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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,28 +201,28 @@ public class GeneralName implements DerEncoder {
/**
* Compare this GeneralName with another
*
- * @param other GeneralName to compare to this
+ * @param obj GeneralName to compare to this
* @return true if match
*/
- public boolean equals(Object other) {
- if (this == other) {
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
return true;
}
- if (!(other instanceof GeneralName))
+ if (!(obj instanceof GeneralName other))
return false;
- GeneralNameInterface otherGNI = ((GeneralName)other).name;
try {
- return name.constrains(otherGNI) == GeneralNameInterface.NAME_MATCH;
+ return name.constrains(other.name)
+ == GeneralNameInterface.NAME_MATCH;
} catch (UnsupportedOperationException ioe) {
return false;
}
}
/**
- * Returns the hash code for this GeneralName.
- *
- * @return a hash code value.
+ * {@return the hash code for this GeneralName}
*/
+ @Override
public int hashCode() {
return name.hashCode();
}
diff --git a/src/java.base/share/classes/sun/security/x509/GeneralSubtree.java b/src/java.base/share/classes/sun/security/x509/GeneralSubtree.java
index 6350740deac..cee5c254cc5 100644
--- a/src/java.base/share/classes/sun/security/x509/GeneralSubtree.java
+++ b/src/java.base/share/classes/sun/security/x509/GeneralSubtree.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -149,30 +149,24 @@ public class GeneralSubtree implements DerEncoder {
/**
* Compare this GeneralSubtree with another
*
- * @param other GeneralSubtree to compare to this
+ * @param obj GeneralSubtree to compare to this
* @return true if match
*/
- public boolean equals(Object other) {
- if (!(other instanceof GeneralSubtree otherGS))
- return false;
- if (this.name == null) {
- if (otherGS.name != null) {
- return false;
- }
- } else {
- if (!((this.name).equals(otherGS.name)))
- return false;
- }
- if (this.minimum != otherGS.minimum)
- return false;
- return this.maximum == otherGS.maximum;
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+
+ return obj instanceof GeneralSubtree other
+ && Objects.equals(this.name, other.name)
+ && this.minimum == other.minimum
+ && this.maximum == other.maximum;
}
/**
- * Returns the hash code for this GeneralSubtree.
- *
- * @return a hash code value.
+ * {@return the hash code for this GeneralSubtree}
*/
+ @Override
public int hashCode() {
if (myhash == -1) {
myhash = 17;
diff --git a/src/java.base/share/classes/sun/security/x509/IPAddressName.java b/src/java.base/share/classes/sun/security/x509/IPAddressName.java
index 0e3be16a2b3..f372d349a57 100644
--- a/src/java.base/share/classes/sun/security/x509/IPAddressName.java
+++ b/src/java.base/share/classes/sun/security/x509/IPAddressName.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2023, 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
@@ -310,6 +310,7 @@ public class IPAddressName implements GeneralNameInterface {
*
* @return true iff the names are identical.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
@@ -334,10 +335,8 @@ public class IPAddressName implements GeneralNameInterface {
}
}
// Now compare masks
- for (int i=maskLen; i < address.length; i++)
- if (address[i] != other[i])
- return false;
- return true;
+ return Arrays.equals(address, maskLen, address.length, other,
+ maskLen, address.length);
} else {
// Two IPv4 host addresses or two IPv6 host addresses
// Compare bytes
@@ -346,17 +345,11 @@ public class IPAddressName implements GeneralNameInterface {
}
/**
- * Returns the hash code value for this object.
- *
- * @return a hash code value for this object.
+ * {@return the hash code value for this object}
*/
+ @Override
public int hashCode() {
- int retval = 0;
-
- for (int i=0; i{@code
* hashCode = getName().hashCode();
* }
- *
- * @return a hash code for this {@code KerberosPrincipal}.
*/
+ @Override
public int hashCode() {
return getName().hashCode();
}
@@ -247,21 +246,18 @@ public final class KerberosPrincipal
* More formally two {@code KerberosPrincipal} instances are equal
* if the values returned by {@code getName()} are equal.
*
- * @param other the object to compare to
+ * @param obj the object to compare to
* @return true if the object passed in represents the same principal
* as this one, false otherwise.
*/
- public boolean equals(Object other) {
+ @Override
+ public boolean equals(Object obj) {
- if (other == this)
+ if (obj == this)
return true;
- if (! (other instanceof KerberosPrincipal)) {
- return false;
- }
- String myFullName = getName();
- String otherFullName = ((KerberosPrincipal) other).getName();
- return myFullName.equals(otherFullName);
+ return obj instanceof KerberosPrincipal other
+ && getName().equals(other.getName());
}
/**
diff --git a/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosTicket.java b/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosTicket.java
index 8bf7fd167ba..d661df6f016 100644
--- a/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosTicket.java
+++ b/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosTicket.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -716,11 +716,10 @@ public class KerberosTicket implements Destroyable, Refreshable,
}
/**
- * Returns a hash code for this {@code KerberosTicket}.
- *
- * @return a hash code for this {@code KerberosTicket}.
+ * {@return a hash code for this {@code KerberosTicket}}
* @since 1.6
*/
+ @Override
public int hashCode() {
int result = 17;
if (isDestroyed()) {
@@ -768,6 +767,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* false otherwise.
* @since 1.6
*/
+ @Override
public boolean equals(Object other) {
if (other == this) {
@@ -792,39 +792,10 @@ public class KerberosTicket implements Destroyable, Refreshable,
return false;
}
- // authTime may be null
- if (authTime == null) {
- if (otherTicket.getAuthTime() != null) {
- return false;
- }
- } else {
- if (!authTime.equals(otherTicket.getAuthTime())) {
- return false;
- }
- }
-
- // startTime may be null
- if (startTime == null) {
- if (otherTicket.getStartTime() != null) {
- return false;
- }
- } else {
- if (!startTime.equals(otherTicket.getStartTime())) {
- return false;
- }
- }
-
- if (renewTill == null) {
- if (otherTicket.getRenewTill() != null) {
- return false;
- }
- } else {
- if (!renewTill.equals(otherTicket.getRenewTill())) {
- return false;
- }
- }
-
- return Objects.equals(proxy, otherTicket.proxy);
+ return Objects.equals(authTime, otherTicket.getAuthTime())
+ && Objects.equals(startTime, otherTicket.getStartTime())
+ && Objects.equals(renewTill, otherTicket.getRenewTill())
+ && Objects.equals(proxy, otherTicket.proxy);
}
/**
diff --git a/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KeyTab.java b/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KeyTab.java
index 375006e7452..5ece73a5a58 100644
--- a/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KeyTab.java
+++ b/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KeyTab.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2023, 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
@@ -328,10 +328,9 @@ public final class KeyTab {
}
/**
- * Returns a hash code for this {@code KeyTab}.
- *
- * @return a hash code for this {@code KeyTab}.
+ * {@return a hash code for this {@code KeyTab}}
*/
+ @Override
public int hashCode() {
return Objects.hash(file, princ, bound);
}
@@ -345,6 +344,7 @@ public final class KeyTab {
* @param other the object to compare to
* @return true if the specified object is equal to this {@code KeyTab}
*/
+ @Override
public boolean equals(Object other) {
if (other == this)
return true;
diff --git a/src/java.security.jgss/share/classes/javax/security/auth/kerberos/ServicePermission.java b/src/java.security.jgss/share/classes/javax/security/auth/kerberos/ServicePermission.java
index 49e94a99fc3..096be775838 100644
--- a/src/java.security.jgss/share/classes/javax/security/auth/kerberos/ServicePermission.java
+++ b/src/java.security.jgss/share/classes/javax/security/auth/kerberos/ServicePermission.java
@@ -240,9 +240,7 @@ public final class ServicePermission extends Permission
}
/**
- * Returns the hash code value for this object.
- *
- * @return a hash code value for this object.
+ * {@return the hash code value for this object}
*/
@Override
public int hashCode() {
diff --git a/src/java.security.jgss/share/classes/org/ietf/jgss/ChannelBinding.java b/src/java.security.jgss/share/classes/org/ietf/jgss/ChannelBinding.java
index 161a5ae3ac7..d5008e7e228 100644
--- a/src/java.security.jgss/share/classes/org/ietf/jgss/ChannelBinding.java
+++ b/src/java.security.jgss/share/classes/org/ietf/jgss/ChannelBinding.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -167,6 +167,7 @@ public class ChannelBinding {
* the same values for the initiator and acceptor addresses and the
* application data.
*/
+ @Override
public boolean equals(Object obj) {
if (this == obj)
@@ -193,17 +194,16 @@ public class ChannelBinding {
}
/**
- * Returns a hashcode value for this ChannelBinding object.
- *
- * @return a hashCode value
+ * {@return a hashcode value for this ChannelBinding object}
*/
+ @Override
public int hashCode() {
if (initiator != null)
return initiator.hashCode();
else if (acceptor != null)
return acceptor.hashCode();
else if (appData != null)
- return new String(appData).hashCode();
+ return Arrays.hashCode(appData);
else
return 1;
}
diff --git a/src/java.security.jgss/share/classes/org/ietf/jgss/GSSCredential.java b/src/java.security.jgss/share/classes/org/ietf/jgss/GSSCredential.java
index 576f64924d2..629a59ca82a 100644
--- a/src/java.security.jgss/share/classes/org/ietf/jgss/GSSCredential.java
+++ b/src/java.security.jgss/share/classes/org/ietf/jgss/GSSCredential.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -358,13 +358,13 @@ public interface GSSCredential extends Cloneable{
* entity; {@code false} otherwise.
* @param another another GSSCredential for comparison to this one
*/
+ @Override
boolean equals(Object another);
/**
- * Returns a hashcode value for this GSSCredential.
- *
- * @return a hashCode value
+ * {@return a hashcode value for this GSSCredential}
*/
+ @Override
int hashCode();
}
diff --git a/src/java.security.jgss/share/classes/org/ietf/jgss/GSSName.java b/src/java.security.jgss/share/classes/org/ietf/jgss/GSSName.java
index 8a541d9fd85..7248a122eb4 100644
--- a/src/java.security.jgss/share/classes/org/ietf/jgss/GSSName.java
+++ b/src/java.security.jgss/share/classes/org/ietf/jgss/GSSName.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -198,13 +198,13 @@ public interface GSSName {
* @param another the object to compare this name to
* @see #equals(GSSName)
*/
+ @Override
boolean equals(Object another);
/**
- * Returns a hashcode value for this GSSName.
- *
- * @return a hashCode value
+ * {@return a hashcode value for this GSSName}
*/
+ @Override
int hashCode();
/**
diff --git a/src/java.security.jgss/share/classes/org/ietf/jgss/Oid.java b/src/java.security.jgss/share/classes/org/ietf/jgss/Oid.java
index ec06ab3b965..e1e2c0fea22 100644
--- a/src/java.security.jgss/share/classes/org/ietf/jgss/Oid.java
+++ b/src/java.security.jgss/share/classes/org/ietf/jgss/Oid.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -150,11 +150,12 @@ public class Oid {
* value, false otherwise.
* @param other the Oid object that has to be compared to this one
*/
+ @Override
public boolean equals(Object other) {
//check if both reference the same object
if (this == other)
- return (true);
+ return true;
if (other instanceof Oid)
return this.oid.equals(((Oid) other).oid);
@@ -205,10 +206,9 @@ public class Oid {
/**
- * Returns a hashcode value for this Oid.
- *
- * @return a hashCode value
+ * {@return a hashcode value for this Oid}
*/
+ @Override
public int hashCode() {
return oid.hashCode();
}
diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/GSSCredentialImpl.java b/src/java.security.jgss/share/classes/sun/security/jgss/GSSCredentialImpl.java
index d6f3816c86b..925f11905bf 100644
--- a/src/java.security.jgss/share/classes/sun/security/jgss/GSSCredentialImpl.java
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/GSSCredentialImpl.java
@@ -476,6 +476,7 @@ public class GSSCredentialImpl implements GSSCredential {
}
}
+ @Override
public boolean equals(Object another) {
if (destroyed) {
@@ -512,10 +513,9 @@ public class GSSCredentialImpl implements GSSCredential {
}
/**
- * Returns a hashcode value for this GSSCredential.
- *
- * @return a hashCode value
+ * {@return a hashcode value for this GSSCredential}
*/
+ @Override
public int hashCode() {
if (destroyed) {
diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/GSSNameImpl.java b/src/java.security.jgss/share/classes/sun/security/jgss/GSSNameImpl.java
index 174a827c3e2..2aedba59ffe 100644
--- a/src/java.security.jgss/share/classes/sun/security/jgss/GSSNameImpl.java
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/GSSNameImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -332,10 +332,9 @@ public final class GSSNameImpl implements GSSName {
}
/**
- * Returns a hashcode value for this GSSName.
- *
- * @return a hashCode value
+ * {@return a hashcode value for this GSSName}
*/
+ @Override
public int hashCode() {
/*
* XXX
@@ -350,6 +349,7 @@ public final class GSSNameImpl implements GSSName {
return 1;
}
+ @Override
public boolean equals(Object another) {
try {
diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/ProviderList.java b/src/java.security.jgss/share/classes/sun/security/jgss/ProviderList.java
index 1813cf1c3ea..c3031779d5e 100644
--- a/src/java.security.jgss/share/classes/sun/security/jgss/ProviderList.java
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/ProviderList.java
@@ -33,6 +33,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Objects;
+
import sun.security.jgss.spi.*;
import sun.security.jgss.wrapper.NativeGSSFactory;
import sun.security.jgss.wrapper.SunNativeProvider;
@@ -448,6 +450,7 @@ public final class ProviderList {
this.oid = oid;
}
+ @Override
public boolean equals(Object other) {
if (this == other) {
return true;
@@ -457,26 +460,13 @@ public final class ProviderList {
return false;
}
- if (this.p.getName().equals(that.p.getName())) {
- if (this.oid != null && that.oid != null) {
- return this.oid.equals(that.oid);
- } else {
- return (this.oid == null && that.oid == null);
- }
- }
-
- return false;
+ return this.p.getName().equals(that.p.getName())
+ && Objects.equals(this.oid, that.oid);
}
+ @Override
public int hashCode() {
- int result = 17;
-
- result = 37 * result + p.getName().hashCode();
- if (oid != null) {
- result = 37 * result + oid.hashCode();
- }
-
- return result;
+ return Objects.hash(p.getName(), oid);
}
/**
diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5NameElement.java b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5NameElement.java
index 24ecbb6106f..e8871735302 100644
--- a/src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5NameElement.java
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5NameElement.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -240,6 +240,7 @@ public class Krb5NameElement
* @return true if they both refer to the same entity, else false
* @see #equals(GSSNameSpi)
*/
+ @Override
public boolean equals(Object another) {
if (this == another) {
return true;
@@ -255,12 +256,11 @@ public class Krb5NameElement
}
/**
- * Returns a hashcode value for this GSSNameSpi.
- *
- * @return a hashCode value
+ * {@return a hashcode value for this GSSNameSpi}
*/
+ @Override
public int hashCode() {
- return 37 * 17 + krb5PrincipalName.getName().hashCode();
+ return krb5PrincipalName.getName().hashCode();
}
diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/spi/GSSNameSpi.java b/src/java.security.jgss/share/classes/sun/security/jgss/spi/GSSNameSpi.java
index 584fe95c791..a2a25825af9 100644
--- a/src/java.security.jgss/share/classes/sun/security/jgss/spi/GSSNameSpi.java
+++ b/src/java.security.jgss/share/classes/sun/security/jgss/spi/GSSNameSpi.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -63,13 +63,13 @@ public interface GSSNameSpi {
* @return true if they both refer to the same entity, else false
* @see #equals(GSSNameSpi)
*/
+ @Override
boolean equals(Object another);
/**
- * Returns a hashcode value for this GSSNameSpi.
- *
- * @return a hashCode value
+ * {@return a hashcode value for this GSSNameSpi}
*/
+ @Override
int hashCode();
/**
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/KrbException.java b/src/java.security.jgss/share/classes/sun/security/krb5/KrbException.java
index 2690cad54c0..3fae5c7c2c5 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/KrbException.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/KrbException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -31,6 +31,8 @@
package sun.security.krb5;
+import java.util.Objects;
+
import sun.security.krb5.internal.Krb5;
import sun.security.krb5.internal.KRBError;
@@ -133,12 +135,7 @@ public class KrbException extends Exception {
}
@Override public int hashCode() {
- int result = 17;
- result = 37 * result + returnCode;
- if (error != null) {
- result = 37 * result + error.hashCode();
- }
- return result;
+ return Objects.hash(returnCode, error);
}
@Override public boolean equals(Object obj) {
@@ -146,15 +143,8 @@ public class KrbException extends Exception {
return true;
}
- if (!(obj instanceof KrbException)) {
- return false;
- }
-
- KrbException other = (KrbException)obj;
- if (returnCode != other.returnCode) {
- return false;
- }
- return (error == null)?(other.error == null):
- (error.equals(other.error));
+ return obj instanceof KrbException other
+ && returnCode == other.returnCode
+ && Objects.equals(error, other.error);
}
}
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/PrincipalName.java b/src/java.security.jgss/share/classes/sun/security/krb5/PrincipalName.java
index 8edf42deddd..d11c96a6613 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/PrincipalName.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/PrincipalName.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -209,12 +209,9 @@ public class PrincipalName implements Cloneable {
if (this == o) {
return true;
}
- if (o instanceof PrincipalName) {
- PrincipalName other = (PrincipalName)o;
- return nameRealm.equals(other.nameRealm) &&
- Arrays.equals(nameStrings, other.nameStrings);
- }
- return false;
+ return o instanceof PrincipalName other
+ && nameRealm.equals(other.nameRealm)
+ && Arrays.equals(nameStrings, other.nameStrings);
}
/**
@@ -513,6 +510,7 @@ public class PrincipalName implements Cloneable {
return temp.toString();
}
+ @Override
public int hashCode() {
return toString().hashCode();
}
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/Realm.java b/src/java.security.jgss/share/classes/sun/security/krb5/Realm.java
index e10d433d57f..44e044a1e1b 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/Realm.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/Realm.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -72,19 +72,17 @@ public class Realm implements Cloneable {
return this;
}
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof Realm)) {
- return false;
- }
-
- Realm that = (Realm)obj;
- return this.realm.equals(that.realm);
+ return obj instanceof Realm that
+ && this.realm.equals(that.realm);
}
+ @Override
public int hashCode() {
return realm.hashCode();
}
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddress.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddress.java
index 3e152476332..6f10c005f9f 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddress.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddress.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -78,43 +78,27 @@ public class HostAddress implements Cloneable {
}
+ @Override
public int hashCode() {
- if (hashCode == 0) {
- int result = 17;
- result = 37*result + addrType;
- if (address != null) {
- for (int i=0; i < address.length; i++) {
- result = 37*result + address[i];
- }
- }
- hashCode = result;
+ int h = hashCode;
+ if (h == 0) {
+ hashCode = h = (37 * addrType + Arrays.hashCode(address));
}
- return hashCode;
-
+ return h;
}
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof HostAddress)) {
+ if (!(obj instanceof HostAddress h)) {
return false;
}
- HostAddress h = (HostAddress)obj;
- if (addrType != h.addrType ||
- (address != null && h.address == null) ||
- (address == null && h.address != null))
- return false;
- if (address != null && h.address != null) {
- if (address.length != h.address.length)
- return false;
- for (int i = 0; i < address.length; i++)
- if (address[i] != h.address[i])
- return false;
- }
- return true;
+ return addrType == h.addrType
+ && Arrays.equals(address, h.address);
}
private static synchronized InetAddress getLocalInetAddress()
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddresses.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddresses.java
index 070ad970bdb..1441624abd2 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddresses.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddresses.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -130,42 +130,26 @@ public class HostAddresses implements Cloneable {
return false;
}
+ @Override
public int hashCode() {
- if (hashCode == 0) {
- int result = 17;
- if (addresses != null) {
- for (int i=0; i < addresses.length; i++) {
- result = 37*result + addresses[i].hashCode();
- }
- }
- hashCode = result;
+ int h = hashCode;
+ if (h == 0) {
+ hashCode = h = Arrays.hashCode(addresses);
}
- return hashCode;
-
+ return h;
}
-
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof HostAddresses)) {
+ if (!(obj instanceof HostAddresses addrs)) {
return false;
}
- HostAddresses addrs = (HostAddresses)obj;
- if ((addresses == null && addrs.addresses != null) ||
- (addresses != null && addrs.addresses == null))
- return false;
- if (addresses != null && addrs.addresses != null) {
- if (addresses.length != addrs.addresses.length)
- return false;
- for (int i = 0; i < addresses.length; i++)
- if (!addresses[i].equals(addrs.addresses[i]))
- return false;
- }
- return true;
+ return Arrays.equals(addresses, addrs.addresses);
}
/**
diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java
index 206bbfc46f5..2b9f69ad536 100644
--- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java
+++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, 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
@@ -44,6 +44,8 @@ import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Objects;
+
import sun.security.krb5.internal.util.KerberosString;
/**
* Implements the ASN.1 KRBError type.
@@ -488,39 +490,34 @@ public class KRBError implements java.io.Serializable {
return true;
}
- if (!(obj instanceof KRBError)) {
+ if (!(obj instanceof KRBError other)) {
return false;
}
- KRBError other = (KRBError)obj;
return pvno == other.pvno &&
msgType == other.msgType &&
- isEqual(cTime, other.cTime) &&
- isEqual(cuSec, other.cuSec) &&
- isEqual(sTime, other.sTime) &&
- isEqual(suSec, other.suSec) &&
errorCode == other.errorCode &&
- isEqual(crealm, other.crealm) &&
- isEqual(cname, other.cname) &&
- isEqual(sname, other.sname) &&
- isEqual(eText, other.eText) &&
- java.util.Arrays.equals(eData, other.eData) &&
- isEqual(eCksum, other.eCksum);
- }
-
- private static boolean isEqual(Object a, Object b) {
- return (a == null)?(b == null):(a.equals(b));
+ Objects.equals(cTime, other.cTime) &&
+ Objects.equals(cuSec, other.cuSec) &&
+ Objects.equals(sTime, other.sTime) &&
+ Objects.equals(suSec, other.suSec) &&
+ Objects.equals(crealm, other.crealm) &&
+ Objects.equals(cname, other.cname) &&
+ Objects.equals(sname, other.sname) &&
+ Objects.equals(eText, other.eText) &&
+ Arrays.equals(eData, other.eData) &&
+ Objects.equals(eCksum, other.eCksum);
}
@Override public int hashCode() {
int result = 17;
result = 37 * result + pvno;
result = 37 * result + msgType;
+ result = 37 * result + errorCode;
if (cTime != null) result = 37 * result + cTime.hashCode();
if (cuSec != null) result = 37 * result + cuSec.hashCode();
if (sTime != null) result = 37 * result + sTime.hashCode();
if (suSec != null) result = 37 * result + suSec.hashCode();
- result = 37 * result + errorCode;
if (crealm != null) result = 37 * result + crealm.hashCode();
if (cname != null) result = 37 * result + cname.hashCode();
if (sname != null) result = 37 * result + sname.hashCode();
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java
index 6b26297b1b4..6d0e7f7353e 100644
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java
@@ -182,6 +182,7 @@ abstract class P11Key implements Key, Length {
abstract byte[] getEncodedInternal();
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -212,20 +213,13 @@ abstract class P11Key implements Key, Length {
return MessageDigest.isEqual(thisEnc, otherEnc);
}
+ @Override
public int hashCode() {
// hashCode() should never throw exceptions
if (!token.isValid()) {
return 0;
}
- byte[] b1 = getEncodedInternal();
- if (b1 == null) {
- return 0;
- }
- int r = b1.length;
- for (int i = 0; i < b1.length; i++) {
- r += (b1[i] & 0xff) * 37;
- }
- return r;
+ return Arrays.hashCode(getEncodedInternal());
}
protected Object writeReplace() throws ObjectStreamException {
diff --git a/test/jdk/jdk/security/logging/TestX509ValidationLog.java b/test/jdk/jdk/security/logging/TestX509ValidationLog.java
index 805cd546729..0880e11f2cc 100644
--- a/test/jdk/jdk/security/logging/TestX509ValidationLog.java
+++ b/test/jdk/jdk/security/logging/TestX509ValidationLog.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2023, 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
@@ -44,9 +44,10 @@ public class TestX509ValidationLog {
l.addExpected("FINE: ValidationChain: " +
TestCertificate.ROOT_CA.certId + ", " +
TestCertificate.ROOT_CA.certId);
+ int hashCode = TestCertificate.ROOT_CA.certificate().getPublicKey().hashCode();
l.addExpected("FINE: ValidationChain: " +
- TestCertificate.ROOT_CA.certificate().getPublicKey().hashCode() +
- ", " + TestCertificate.ROOT_CA.certId);
+ Integer.toUnsignedLong(hashCode) + ", " +
+ TestCertificate.ROOT_CA.certId);
l.testExpected();
}