Skip to content
This repository was archived by the owner on Feb 23, 2018. It is now read-only.

Commit 3218387

Browse files
committed
Fix findItemByIndex in case of hash collisions
The method `findItemByIndex` only looked at the first item in each bucket of the `items` hash table. Also, in case the item was not found, the counter `i` would be at `items.length`, therefore the access `items[i]` crashed with an ArrayIndexOutOfBoundsException. Fixes the issue scala/scala-asm#8.
1 parent 6b478ad commit 3218387

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/java/scala/tools/asm/ClassWriter.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,12 +1747,20 @@ private void put(final Item i) {
17471747
}
17481748

17491749
/**
1750-
* Find item that whose index is `index`.
1750+
* Returns the item with a specific index.
1751+
*
1752+
* @param index
1753+
* the index of the searched item.
1754+
* @return the item with the given index.
17511755
*/
17521756
public Item findItemByIndex(int index) {
1753-
int i = 0;
1754-
while (i < items.length && (items[i] == null || items[i].index != index)) i++;
1755-
return items[i];
1757+
for (Item item : items) {
1758+
while (item != null) {
1759+
if (item.index == index) return item;
1760+
item = item.next;
1761+
}
1762+
}
1763+
return null;
17561764
}
17571765

17581766
/**

0 commit comments

Comments
 (0)