mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8186654: Poor quality of sun.security.util.Cache.EqualByteArray.hashCode()
Reviewed-by: coffeys
This commit is contained in:
parent
4560687884
commit
9c1b0103b3
2 changed files with 47 additions and 7 deletions
|
@ -164,7 +164,7 @@ public abstract class Cache<K,V> {
|
|||
public static class EqualByteArray {
|
||||
|
||||
private final byte[] b;
|
||||
private volatile int hash;
|
||||
private int hash;
|
||||
|
||||
public EqualByteArray(byte[] b) {
|
||||
this.b = b;
|
||||
|
@ -172,12 +172,8 @@ public abstract class Cache<K,V> {
|
|||
|
||||
public int hashCode() {
|
||||
int h = hash;
|
||||
if (h == 0) {
|
||||
h = b.length + 1;
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
h += (b[i] & 0xff) * 37;
|
||||
}
|
||||
hash = h;
|
||||
if (h == 0 && b.length > 0) {
|
||||
hash = h = Arrays.hashCode(b);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue