summaryrefslogtreecommitdiff
path: root/src/asm
diff options
context:
space:
mode:
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;