Skip to content

Commit 6aa23c0

Browse files
committed
fix: Negative hash again
1 parent b9c6cec commit 6aa23c0

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

config/src/main/java/com/typesafe/config/impl/BadMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ BadMap<K,V> copyingPut(K k, V v) {
6868
}
6969

7070
private static <K,V> void store(Entry[] entries, int hash, K k, V v) {
71-
int i = hash % entries.length;
71+
int i = Math.abs(hash % entries.length);
7272
Entry old = entries[i]; // old may be null
7373
entries[i] = new Entry(hash, k, v, old);
7474
}

config/src/test/scala/com/typesafe/config/impl/BadMapTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class BadMapTest extends TestUtils {
9898
val negativeHashKey = new Key(Integer.MIN_VALUE)
9999
map = map.copyingPut(negativeHashKey, "value")
100100
.copyingPut(new Key(2), "other value")
101+
.copyingPut(new Key(Integer.MIN_VALUE), "negative again")
101102
.copyingPut(new Key(3), "yet another value")
102103
assertEquals(map.get(negativeHashKey), "value")
103104
}

0 commit comments

Comments
 (0)