Permalink
Browse files

check added instruction to ASM MethodNode

  • Loading branch information...
1 parent 10845ad commit b50e6b4bbe174768021f75c63f0d750ebfa9f2a5 @magarciaEPFL magarciaEPFL committed Apr 25, 2013
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/asm/scala/tools/asm/tree/InsnList.java
@@ -244,6 +244,14 @@ public void set(final AbstractInsnNode location, final AbstractInsnNode insn) {
* {@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;

0 comments on commit b50e6b4

Please sign in to comment.