From 40d3223b128887dffafb8d6f28438628ad72e039 Mon Sep 17 00:00:00 2001 From: chibash Date: Wed, 15 Nov 2017 07:02:05 +0900 Subject: fixes a bug reported in issue #155 (Javassist Incorrect Code when wrapping with try/catch) --- src/test/javassist/JvstTest5.java | 17 +++++++++++++++++ src/test/test5/Issue155.java | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/test/test5/Issue155.java (limited to 'src/test') diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index e7fdb28c..6f6eb075 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -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 index 00000000..3782e10d --- /dev/null +++ b/src/test/test5/Issue155.java @@ -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(); + } +} -- cgit v1.2.3