]> source.dussan.org Git - javassist.git/commitdiff
fixes a bug reported in issue #155 (Javassist Incorrect Code when wrapping with try...
authorchibash <chiba@javassist.org>
Tue, 14 Nov 2017 22:02:05 +0000 (07:02 +0900)
committerchibash <chiba@javassist.org>
Tue, 14 Nov 2017 22:02:05 +0000 (07:02 +0900)
javassist.jar
src/main/javassist/bytecode/stackmap/MapMaker.java
src/test/javassist/JvstTest5.java
src/test/test5/Issue155.java [new file with mode: 0644]

index 9ae3c4bd585ce0012448c5adf94d768e6df2903a..232bb340746efd217029ecaea41a59dbf0f82f19 100644 (file)
Binary files a/javassist.jar and b/javassist.jar differ
index 538fba672406e81c4d57a6d25c2e8cd21302c0ce..bd79377fdde63df9d0dee5148370e590141e83c4 100644 (file)
@@ -430,7 +430,6 @@ public class MapMaker extends Tracer {
                 // dead code.
                 writer.sameFrame(offsetDelta);
                 offsetDelta = bb.length - 1;
-                prev = bb;
             }
             else
                 offsetDelta += bb.length;
index e7fdb28c92617031dc826d7dda1a38c16d5a1704..6f6eb0759604fbf598e2f52d4522e301cf58e862 100644 (file)
@@ -10,6 +10,7 @@ import javassist.bytecode.ClassFile;
 import javassist.bytecode.ConstPool;
 import javassist.bytecode.InnerClassesAttribute;
 import javassist.expr.ExprEditor;
+import javassist.expr.Handler;
 import javassist.expr.MethodCall;
 
 @SuppressWarnings({"rawtypes","unchecked","unused"})
@@ -399,4 +400,20 @@ public class JvstTest5 extends JvstTestRoot {
         assertTrue(Modifier.isVarArgs(cc.getDeclaredMethod("foo").getModifiers()));
         assertFalse(Modifier.isVarArgs(cc.getDeclaredMethod("bar").getModifiers()));
     }
+
+    public void testIssue155() throws Exception {
+        CtClass cc = sloader.get("test5.Issue155");
+        CtMethod testMethod = cc.getDeclaredMethod("foo");
+        testMethod.instrument(
+                new ExprEditor() {
+                    public void edit(Handler m)
+                            throws CannotCompileException {
+                        m.insertBefore("throw $1;");
+                    }
+                });
+
+        cc.writeFile();
+        Object obj = make(cc.getName());
+        assertEquals(1, invoke(obj, "test"));
+    }
 }
diff --git a/src/test/test5/Issue155.java b/src/test/test5/Issue155.java
new file mode 100644 (file)
index 0000000..3782e10
--- /dev/null
@@ -0,0 +1,22 @@
+package test5;
+
+public class Issue155 {
+    public void bar() {}
+
+    public void foo() throws Throwable {
+        try {
+            bar();
+        } catch (java.lang.IllegalArgumentException e) {
+            bar();
+        }
+    }
+
+    public int test() throws Throwable {
+        foo();
+        return 1;
+    }
+
+    public static void main(String[] args) throws Throwable {
+        new Issue155().foo();
+    }
+}