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

Consistently assert that instructions are not already owned

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