RFR: 8311170: Simplify and modernize equals and hashCode in security area [v12]

Valerie Peng valeriep at openjdk.org
Mon Aug 7 21:06:39 UTC 2023


On Fri, 4 Aug 2023 15:11:47 GMT, Pavel Rappo <prappo at openjdk.org> wrote:

>> src/java.base/share/classes/sun/security/provider/certpath/CertId.java line 182:
>> 
>>> 180:             myhash += Arrays.hashCode(issuerNameHash);
>>> 181:             myhash += Arrays.hashCode(issuerKeyHash);
>>> 182:             myhash += certSerialNumber.getNumber().hashCode();
>> 
>> It seems that for some other classes, you may just use Objects.hash(hashAlgId, issuerNameHash, issuerKeyHash, certSerialNumber.getNumber())? Is there a rule on what to use?
>
> We can be more aggressive in some refactorings, but I note that if any of the hashCode components are arrays, the proper, albeit slightly inconvenient way to combine all the components would be `Arrays.deepHashCode(Object[])`, not `Objects.hash(Object... values)` or `Arrays.hashCode(Object[])`. The latter two don't recurse into arrays, but use their "shallow" hashCode.

Hmm, I see. Thanks for the clarification.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14738#discussion_r1286381949


More information about the security-dev mailing list