From 705c3c66218afb4d914a00323d5acad6c062683e Mon Sep 17 00:00:00 2001 From: chiba Date: Sat, 20 Oct 2012 10:57:51 +0000 Subject: fixed JASSIST-175 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@675 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/test/javassist/bytecode/StackMapTest.java | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/test/javassist') diff --git a/src/test/javassist/bytecode/StackMapTest.java b/src/test/javassist/bytecode/StackMapTest.java index 876b335e..0fdcf2cd 100644 --- a/src/test/javassist/bytecode/StackMapTest.java +++ b/src/test/javassist/bytecode/StackMapTest.java @@ -647,6 +647,66 @@ public class StackMapTest extends TestCase { } } + public void testJIRA175() throws Exception { + CtClass cc = loader.get("javassist.bytecode.StackMapTest$C5"); + cc.getDeclaredMethod("setter").instrument(new javassist.expr.ExprEditor() { + @Override + public void edit(javassist.expr.FieldAccess f) throws javassist.CannotCompileException { + if (!f.where().getMethodInfo().isMethod()) + return; + + f.replace("{ $_ = $proceed($$); if (false) return $_;}"); + } + }); + cc.writeFile(); + Object t1 = make(cc.getName()); + assertEquals(3, invoke(t1, "test")); + } + + public static class C5 { + String value; + int ivalue; + public int test() { + setter("foo"); + return value.length(); + } + + public void setter(String s) { + value = s; + ivalue = s.length(); + } + } + + public void testJIRA175b() throws Exception { + CtClass cc = loader.get("javassist.bytecode.StackMapTest$C6"); + try { + cc.getDeclaredMethod("setter").instrument(new javassist.expr.ExprEditor() { + public void edit(javassist.expr.FieldAccess f) throws javassist.CannotCompileException { + if (!f.where().getMethodInfo().isMethod()) + return; + + f.replace("{ $_ = $proceed($$); return $_;}"); + } + }); + fail("deadcode detection"); + } + catch (javassist.CannotCompileException e) {} + } + + public static class C6 { + String value; + int ivalue; + public int test() { + setter("foo"); + return value.length(); + } + + public void setter(String s) { + value = s; + ivalue = s.length(); + } + } + public void tstCtClassType() throws Exception { ClassPool cp = ClassPool.getDefault(); CtClass cc = cp.get("javassist.CtClassType"); -- cgit v1.2.3