Commit f2432c3a authored by ebruneton's avatar ebruneton
Browse files

Fixed bug #317607.

parent 6f494c31
......@@ -178,7 +178,7 @@ public class InsnList {
*
* @param index
* index of instruction for the iterator to start at
*
*
* @return an iterator over the instructions in this list.
*/
@SuppressWarnings("unchecked")
......@@ -605,14 +605,28 @@ public class InsnList {
}
public void add(Object o) {
InsnList.this.insertBefore(next, (AbstractInsnNode) o);
if (next != null) {
InsnList.this.insertBefore(next, (AbstractInsnNode) o);
} else if (prev != null) {
InsnList.this.insert(prev, (AbstractInsnNode) o);
} else {
InsnList.this.add((AbstractInsnNode) o);
}
prev = (AbstractInsnNode) o;
remove = null;
}
public void set(Object o) {
InsnList.this.set(next.prev, (AbstractInsnNode) o);
prev = (AbstractInsnNode) o;
if (remove != null) {
InsnList.this.set(remove, (AbstractInsnNode) o);
if (remove == prev) {
prev = (AbstractInsnNode) o;
} else {
next = (AbstractInsnNode) o;
}
} else {
throw new IllegalStateException();
}
}
}
}
......@@ -250,6 +250,35 @@ public class InsnListUnitTest extends TestCase {
}
}
public void testIterator5() {
// Call add() on empty list
ListIterator<AbstractInsnNode> it = l1.iterator();
it.add(new InsnNode(0));
assertEquals(1, l1.size());
// Call set() at end of list
it = l1.iterator();
it.next();
it.set(new InsnNode(1));
assertEquals(1, l1.size());
assertEquals(1, l1.get(0).opcode);
// Call add() at end of list
it = l2.iterator();
it.next();
it.next();
it.add(new InsnNode(0));
assertEquals(3, l2.size());
// next() after set(), itself after previous()
it = l2.iterator();
it.next();
it.next();
it.previous();
it.set(new InsnNode(1));
assertEquals(1, it.next().opcode);
}
public void testInvalidIndexOf() {
try {
l1.indexOf(new InsnNode(0));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment