diff options
author | chibash <chiba@javassist.org> | 2017-11-15 07:02:05 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2017-11-15 07:02:05 +0900 |
commit | 40d3223b128887dffafb8d6f28438628ad72e039 (patch) | |
tree | 9767c69e56b4fb49d22c877b06f353ae6f278d77 /src/test | |
parent | bdc2b3784c99c5ca54a549af8f2015aaa15699dd (diff) | |
download | javassist-40d3223b128887dffafb8d6f28438628ad72e039.tar.gz javassist-40d3223b128887dffafb8d6f28438628ad72e039.zip |
fixes a bug reported in issue #155 (Javassist Incorrect Code when wrapping with try/catch)
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/javassist/JvstTest5.java | 17 | ||||
-rw-r--r-- | src/test/test5/Issue155.java | 22 |
2 files changed, 39 insertions, 0 deletions
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(); + } +} |