diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-02-19 12:41:47 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-02-19 12:41:47 +0000 |
commit | e50d7c0862acc66ca1d6b26ec126eb3ed5295d7d (patch) | |
tree | a469d5da08dc4ad80401739f827974606ac8621b /src/test | |
parent | 205b65d96c5fb9d0086eb98d31e21e927d79cf27 (diff) | |
download | javassist-e50d7c0862acc66ca1d6b26ec126eb3ed5295d7d.tar.gz javassist-e50d7c0862acc66ca1d6b26ec126eb3ed5295d7d.zip |
fixed JASSIST-152
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@615 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/Jassist150.java | 20 | ||||
-rw-r--r-- | src/test/javassist/JvstTest4.java | 16 | ||||
-rw-r--r-- | src/test/test4/JIRA152.java | 60 |
3 files changed, 94 insertions, 2 deletions
diff --git a/src/test/Jassist150.java b/src/test/Jassist150.java index 1435e274..d3945069 100644 --- a/src/test/Jassist150.java +++ b/src/test/Jassist150.java @@ -3,6 +3,8 @@ import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; import javassist.NotFoundException; +import javassist.expr.ExprEditor; +import javassist.expr.MethodCall; public class Jassist150 { public static final String BASE_PATH = "./"; @@ -77,7 +79,23 @@ public class Jassist150 { ccGet.setBody(code3); } - public static void main(String[] args) { + public void testJIRA152() throws Exception { + CtClass cc = ClassPool.getDefault().get("test4.JIRA152"); + CtMethod mth = cc.getDeclaredMethod("buildColumnOverride"); + mth.instrument(new ExprEditor() { + public void edit(MethodCall c) throws CannotCompileException { + c.replace("try{ $_ = $proceed($$); } catch (Throwable t) { throw t; }"); + } + }); + mth.getMethodInfo().rebuildStackMap(ClassPool.getDefault()); + cc.writeFile(); + } + + public static void main(String[] args) throws Exception { + new Jassist150().testJIRA152(); + } + + public static void main2(String[] args) { for (int loop = 0; loop < 5; loop++) { try { implTestClassTailCache(); diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index 4070eb74..a3c47ee1 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -85,7 +85,7 @@ public class JvstTest4 extends JvstTestRoot { } } }); - // m3.getMethodInfo2().rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2()); + m3.getMethodInfo().rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile()); cc.writeFile(); Object obj = make(cc.getName()); @@ -687,4 +687,18 @@ public class JvstTest4 extends JvstTestRoot { System.out.println("JIRA150b " + size); assertTrue(size < N - 10); } + + public void testJIRA152() throws Exception { + CtClass cc = sloader.get("test4.JIRA152"); + CtMethod mth = cc.getDeclaredMethod("buildColumnOverride"); + //CtMethod mth = cc.getDeclaredMethod("tested"); + mth.instrument(new ExprEditor() { + public void edit(MethodCall c) throws CannotCompileException { + c.replace("try{ $_ = $proceed($$); } catch (Throwable t) { throw t; }"); + } + }); + cc.writeFile(); + Object obj = make(cc.getName()); + assertEquals(1, invoke(obj, "test")); + } } diff --git a/src/test/test4/JIRA152.java b/src/test/test4/JIRA152.java new file mode 100644 index 00000000..8fba32a1 --- /dev/null +++ b/src/test/test4/JIRA152.java @@ -0,0 +1,60 @@ +package test4; + +import java.util.Map; +import java.util.HashMap; + +public class JIRA152 { + public int foo(int i) { return i; } + public int bar(int j) { return j; } + public int tested(int k) { + String[] p; + if (k > 0) + p = new String[1]; + else + p = null; + + if (p != null) + while (k < p.length) + k++; + + return 0; + } + + public String put(String s, Object obj) { + return s; + } + + private static Map<String, String[]> buildColumnOverride(JIRA152 element, String path) { + Map<String, String[]> columnOverride = new HashMap<String, String[]>(); + if ( element == null ) return null; + String singleOverride = element.toString(); + String multipleOverrides = element.toString(); + String[] overrides; + if ( singleOverride != null ) { + overrides = new String[] { singleOverride }; + } + /*else if ( multipleOverrides != null ) { + // overrides = columnOverride.get("foo"); + overrides = null; + }*/ + else { + overrides = null; + } + + if ( overrides != null ) { + for (String depAttr : overrides) { + columnOverride.put( + element.put(path, depAttr.getClass()), + new String[] { depAttr.toLowerCase() } + ); + //columnOverride.put("a", new String[1]); + } + } + return columnOverride; + } + + public int test() { + Map<String,String[]> map = buildColumnOverride(this, "foo"); + return map.size(); + } +} |