Skip to content

Commit

Permalink
[asm-cherry-pick] Ensure instructions belong only to one list
Browse files Browse the repository at this point in the history
Fail early when adding an instruction that already belongs to a
different instruction list.

Cherry-pick of b50e6b4.
  • Loading branch information
magarciaEPFL authored and lrytz committed Mar 14, 2015
1 parent 9a7e518 commit eccd0dc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/asm/scala/tools/asm/tree/InsnList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eccd0dc

Please sign in to comment.