From: chiba Date: Sun, 19 Feb 2012 12:41:47 +0000 (+0000) Subject: fixed JASSIST-152 X-Git-Tag: rel_3_17_1_ga~45 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e50d7c0862acc66ca1d6b26ec126eb3ed5295d7d;p=javassist.git fixed JASSIST-152 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@615 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/Readme.html b/Readme.html index 2553a29f..022268c5 100644 --- a/Readme.html +++ b/Readme.html @@ -283,7 +283,7 @@ see javassist.Dump.

-version 3.16

diff --git a/src/main/javassist/bytecode/stackmap/TypeData.java b/src/main/javassist/bytecode/stackmap/TypeData.java index 65ab226e..cef23211 100644 --- a/src/main/javassist/bytecode/stackmap/TypeData.java +++ b/src/main/javassist/bytecode/stackmap/TypeData.java @@ -284,7 +284,7 @@ public abstract class TypeData { } } - /* See also NullType.getExpected(). + /* See also {NullType,ArrayElement}.getExpected(). */ public String getExpected() throws BadBytecode { ArrayList equiv = equivalences; @@ -410,19 +410,38 @@ public abstract class TypeData { } public String getName() throws BadBytecode { - String name = array.getName(); + return getName2(array.getName()); + } + + private String getName2(String name) throws BadBytecode { if (name.length() > 1 && name.charAt(0) == '[') { char c = name.charAt(1); if (c == 'L') - return name.substring(2, name.length() - 1).replace('/', '.'); + return name.substring(2, name.length() - 1).replace('/', '.'); else if (c == '[') return name.substring(1); } - - throw new BadBytecode("bad array type for AALOAD: " + + if (array.isNullType()) + return "java.lang.Object"; + else + throw new BadBytecode("bad array type for AALOAD: " + name); } + public String getExpected() throws BadBytecode { + ArrayList equiv = equivalences; + if (equiv.size() == 1) + return getName2(array.getExpected()); // not getName(); + else { + String en = expectedName; + if (en == null) + return "java.lang.Object"; + else + return en; + } + } + public static String getArrayType(String elementType) { if (elementType.charAt(0) == '[') return "[" + elementType; 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 buildColumnOverride(JIRA152 element, String path) { + Map columnOverride = new HashMap(); + 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 map = buildColumnOverride(this, "foo"); + return map.size(); + } +}