summaryrefslogtreecommitdiff
path: root/src/asm
diff options
context:
space:
mode:
authorMiguel Garcia <miguelalfredo.garcia@epfl.ch>2013-04-25 10:52:35 +0200
committerMiguel Garcia <miguelalfredo.garcia@epfl.ch>2013-04-25 10:52:35 +0200
commitb50e6b4bbe174768021f75c63f0d750ebfa9f2a5 (patch)
treec68cab30b4c2cd26de3da99dbace7b2e697f1785 /src/asm
parent10845adebe741fc2bb5bce70df0a8da7788aa722 (diff)
downloadscala-b50e6b4bbe174768021f75c63f0d750ebfa9f2a5.tar.gz
scala-b50e6b4bbe174768021f75c63f0d750ebfa9f2a5.tar.bz2
scala-b50e6b4bbe174768021f75c63f0d750ebfa9f2a5.zip
check added instruction to ASM MethodNode
Diffstat (limited to 'src/asm')
-rw-r--r--src/asm/scala/tools/asm/tree/InsnList.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/asm/scala/tools/asm/tree/InsnList.java b/src/asm/scala/tools/asm/tree/InsnList.java
index 55d83c2e8b..b1e2d97c6f 100644
--- a/src/asm/scala/tools/asm/tree/InsnList.java
+++ b/src/asm/scala/tools/asm/tree/InsnList.java
@@ -244,6 +244,14 @@ public class InsnList {
* {@link InsnList}</i>.
*/
public void add(final AbstractInsnNode insn) {
+ if(insn.prev != null || insn.next != null) {
+ // Adding an instruction that still refers to others (in the same or another InsnList) leads to hard to debug bugs.
+ // Initially everything may look ok (e.g. iteration follows `next` thus a stale `prev` isn't noticed).
+ // However, a stale link brings the doubly-linked into disarray e.g. upon removing an element,
+ // which results in the `next` of a stale `prev` being updated, among other failure scenarios.
+ // Better fail early.
+ throw new RuntimeException("Instruction " + insn + " already belongs to some InsnList.");
+ }
++size;
if (last == null) {
first = insn;