Skip to content

Commit 509644d

Browse files
committed
Remove hashCode caching since it could introduce very subtle bugs
1 parent b54f292 commit 509644d

File tree

2 files changed

+1
-10
lines changed

2 files changed

+1
-10
lines changed

src/main/java/at/favre/lib/bytes/Bytes.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ public static Bytes random(int length, Random random) {
745745
private final byte[] byteArray;
746746
private final ByteOrder byteOrder;
747747
private final BytesFactory factory;
748-
private transient int hashCodeCache;
749748

750749
Bytes(byte[] byteArray, ByteOrder byteOrder) {
751750
this(byteArray, byteOrder, new Factory());
@@ -2221,10 +2220,7 @@ public boolean equalsContent(Bytes other) {
22212220

22222221
@Override
22232222
public int hashCode() {
2224-
if (hashCodeCache == 0) {
2225-
hashCodeCache = Util.Obj.hashCode(internalArray(), byteOrder());
2226-
}
2227-
return hashCodeCache;
2223+
return Util.Obj.hashCode(internalArray(), byteOrder());
22282224
}
22292225

22302226
/**

src/main/java/at/favre/lib/bytes/MutableBytes.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,6 @@ public Bytes immutable() {
178178
return Bytes.wrap(internalArray(), byteOrder());
179179
}
180180

181-
@Override
182-
public int hashCode() {
183-
return Util.Obj.hashCode(internalArray(), byteOrder());
184-
}
185-
186181
@Override
187182
public boolean equals(Object o) {
188183
return super.equals(o);

0 commit comments

Comments
 (0)