Inserting to InsnList before several nodes
I am trying to: 1) Iterate instructions and find all relevant nodes 2) Insert custom code before found nodes I used streams and iterator to make it and insert, which works only for the first node InsnList instructions = methodNode.instructions; InsnList addition = ... //It work: found n nodes for n return instructions Stream<AbstractInsnNode> returnNodes = Stream.iterate(instructions.getFirst(), AbstractInsnNode::getNext).limit(instructions.size()) .filter(n -> returnOpcodes.contains(n.getOpcode())); //It not work: inserted only before first node returnNodes.forEach(n -> instructions