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

Commit 81194e2

Browse files
lrytzCarsten Varming
authored and
Carsten Varming
committed
[asm-cherry-pick] 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 4a7bb6a commit 81194e2

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
@@ -1782,12 +1782,20 @@ private void put(final Item i) {
17821782
}
17831783

17841784
/**
1785-
* Find item that whose index is `index`.
1785+
* Returns the item with a specific index.
1786+
*
1787+
* @param index
1788+
* the index of the searched item.
1789+
* @return the item with the given index.
17861790
*/
17871791
public Item findItemByIndex(int index) {
1788-
int i = 0;
1789-
while (i < items.length && (items[i] == null || items[i].index != index)) i++;
1790-
return items[i];
1792+
for (Item item : items) {
1793+
while (item != null) {
1794+
if (item.index == index) return item;
1795+
item = item.next;
1796+
}
1797+
}
1798+
return null;
17911799
}
17921800

17931801
/**

0 commit comments

Comments
 (0)