From 2ad671e1f98b0afdbfade0fe818f2d2330dd9134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Mon, 26 Oct 2020 07:52:47 +0800 Subject: [PATCH] use add instead of insert --- .../alibaba/testable/agent/handler/TestClassHandler.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/TestClassHandler.java b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/TestClassHandler.java index e784566..5332de9 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/TestClassHandler.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/TestClassHandler.java @@ -85,12 +85,11 @@ public class TestClassHandler extends BaseClassHandler { private AbstractInsnNode[] replaceTestableUtilField(MethodNode mn, AbstractInsnNode[] instructions, String fieldName, int pos) { - InsnList insnNodes = new InsnList(); - // NOTE: will insert in reversed order - insnNodes.insert(new MethodInsnNode(INVOKESTATIC, CLASS_TESTABLE_UTIL, FIELD_TO_METHOD_MAPPING.get(fieldName), + InsnList il = new InsnList(); + il.add(new VarInsnNode(ALOAD, 0)); + il.add(new MethodInsnNode(INVOKESTATIC, CLASS_TESTABLE_UTIL, FIELD_TO_METHOD_MAPPING.get(fieldName), SIGNATURE_TESTABLE_UTIL_METHOD, false)); - insnNodes.insert(new VarInsnNode(ALOAD, 0)); - mn.instructions.insert(instructions[pos], insnNodes); + mn.instructions.insert(instructions[pos], il); mn.instructions.remove(instructions[pos]); return mn.instructions.toArray(); }