Skip to content

Commit c3293d1

Browse files
committed
Correctly set newTable field in ConcurrentLong2ReferenceChainedHashTable
Fixes exceptions occurring during read/writes to map while table is resizing.
1 parent cda6b98 commit c3293d1

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/main/java/ca/spottedleaf/concurrentutil/map/ConcurrentLong2ReferenceChainedHashTable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected ConcurrentLong2ReferenceChainedHashTable(final int capacity, final flo
123123

124124
this.loadFactor = loadFactor;
125125
// noinspection unchecked
126-
this.table = (TableEntry<V>[])new TableEntry[tableSize];
126+
this.nextTable = this.table = (TableEntry<V>[])new TableEntry[tableSize];
127127
}
128128

129129
public static <V> ConcurrentLong2ReferenceChainedHashTable<V> createWithCapacity(final int capacity) {
@@ -367,6 +367,7 @@ private void resize(final long sum) {
367367

368368
// does not need to be volatile read, just plain
369369
final TableEntry<V>[] oldTable = this.table;
370+
this.nextTable = newTable;
370371

371372
// when resizing, the old entries at bin i (where i = hash % oldTable.length) are assigned to
372373
// bin k in the new table (where k = hash % newTable.length)

0 commit comments

Comments
 (0)