aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/javassist
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-10-20 10:57:51 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-10-20 10:57:51 +0000
commit705c3c66218afb4d914a00323d5acad6c062683e (patch)
tree4fcaa70634d20167d7f7983e8dfae8dbc06c94b7 /src/test/javassist
parent34a093c27a90fdcb8f463f2b3ee74e612dcc12f8 (diff)
downloadjavassist-705c3c66218afb4d914a00323d5acad6c062683e.tar.gz
javassist-705c3c66218afb4d914a00323d5acad6c062683e.zip
fixed JASSIST-175
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@675 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/test/javassist')
-rw-r--r--src/test/javassist/bytecode/StackMapTest.java60
1 files changed, 60 insertions, 0 deletions
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");