Commit 2056c3b8 authored by Jason Zaugg's avatar Jason Zaugg

Consistently assert that instructions are not already owned

parent bc33e850
......@@ -190,6 +190,7 @@ public class InsnList {
* @param newInsnNode another instruction, <i>which must not belong to any {@link InsnList}</i>.
*/
public void set(final AbstractInsnNode oldInsnNode, final AbstractInsnNode newInsnNode) {
ensureNotOwned(newInsnNode);
AbstractInsnNode nextInsn = oldInsnNode.nextInsn;
newInsnNode.nextInsn = nextInsn;
if (nextInsn != null) {
......@@ -266,6 +267,7 @@ public class InsnList {
* @param insnNode an instruction, <i>which must not belong to any {@link InsnList}</i>.
*/
public void insert(final AbstractInsnNode insnNode) {
ensureNotOwned(insnNode);
++size;
if (firstInsn == null) {
firstInsn = insnNode;
......@@ -311,6 +313,7 @@ public class InsnList {
* InsnList}</i>.
*/
public void insert(final AbstractInsnNode previousInsn, final AbstractInsnNode insnNode) {
ensureNotOwned(insnNode);
++size;
AbstractInsnNode nextInsn = previousInsn.nextInsn;
if (nextInsn == null) {
......@@ -361,6 +364,7 @@ public class InsnList {
* InsnList}</i>.
*/
public void insertBefore(final AbstractInsnNode nextInsn, final AbstractInsnNode insnNode) {
ensureNotOwned(insnNode);
++size;
AbstractInsnNode previousInsn = nextInsn.previousInsn;
if (previousInsn == null) {
......
......@@ -752,7 +752,14 @@ public class InsnListTest {
@Test
public void testAddNodeAssociatedWithAnotherList() {
InsnNode insnNode = new InsnNode(0);
assertThrows(IllegalArgumentException.class, () -> list3Unchecked.add(insn1));
assertThrows(IllegalArgumentException.class, () -> list3Unchecked.insert(insn1));
list3Unchecked.insert(insnNode);
assertThrows(IllegalArgumentException.class, () -> list3Unchecked.insert(insnNode, insn1));
assertThrows(IllegalArgumentException.class, () -> list3Unchecked.insertBefore(insnNode, insn1));
assertThrows(IllegalArgumentException.class, () -> list3Unchecked.set(insnNode, insn1));
assertThrows(IllegalArgumentException.class, () -> list3Unchecked.set(insnNode, insn1));
}
/** An InsnList which checks that its methods are properly used. */
......
Markdown is supported
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