diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-11-04 13:51:12 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-11-04 13:51:12 +0000 |
commit | 4453e36043b556dabbf22662904f7985a76bb445 (patch) | |
tree | 6355ae32f1ed69d20c08dfb75df99488add9e129 | |
parent | a904f21c6dead5d668205119241bc4206d70d064 (diff) | |
download | javassist-4453e36043b556dabbf22662904f7985a76bb445.tar.gz javassist-4453e36043b556dabbf22662904f7985a76bb445.zip |
fixed JASSIST-176
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@677 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | Readme.html | 2 | ||||
-rw-r--r-- | javassist.jar | bin | 700680 -> 700785 bytes | |||
-rw-r--r-- | src/main/javassist/bytecode/stackmap/TypeData.java | 15 | ||||
-rw-r--r-- | src/test/javassist/bytecode/StackMapTest.java | 72 |
4 files changed, 84 insertions, 5 deletions
diff --git a/Readme.html b/Readme.html index 4a5e00a6..291324d0 100644 --- a/Readme.html +++ b/Readme.html @@ -284,7 +284,7 @@ see javassist.Dump. <p>-version 3.17 <ul> <li>OSGi bundle info is now included in the jar file. - <li>JIRA JASSIST-160, 163, 166, 168, 170, 171, 174, 175 have been fixed. + <li>JIRA JASSIST-160, 163, 166, 168, 170, 171, 174, 175, 176 have been fixed. </ul> <p>-version 3.16.1 on March 6, 2012 diff --git a/javassist.jar b/javassist.jar Binary files differindex 6cd27e1c..a50f8a70 100644 --- a/javassist.jar +++ b/javassist.jar diff --git a/src/main/javassist/bytecode/stackmap/TypeData.java b/src/main/javassist/bytecode/stackmap/TypeData.java index e45fee0e..363aa241 100644 --- a/src/main/javassist/bytecode/stackmap/TypeData.java +++ b/src/main/javassist/bytecode/stackmap/TypeData.java @@ -388,17 +388,24 @@ public abstract class TypeData { * by considering array types. */ public static CtClass commonSuperClassEx(CtClass one, CtClass two) throws NotFoundException { - if (one.isArray() && two.isArray()) { + if (one == two) + return one; + else if (one.isArray() && two.isArray()) { CtClass ele1 = one.getComponentType(); CtClass ele2 = two.getComponentType(); - CtClass element = commonSuperClassEx(ele1, ele2); + CtClass element = commonSuperClassEx(ele1, ele2); if (element == ele1) return one; else if (element == ele2) return two; - - return one.getClassPool().get(element.getName() + "[]"); + else + return one.getClassPool().get(element == null ? "java.lang.Object" + : element.getName() + "[]"); } + else if (one.isPrimitive() || two.isPrimitive()) + return null; // TOP + else if (one.isArray() || two.isArray()) // but !(one.isArray() && two.isArray()) + return one.getClassPool().get("java.lang.Object"); else return commonSuperClass(one, two); } diff --git a/src/test/javassist/bytecode/StackMapTest.java b/src/test/javassist/bytecode/StackMapTest.java index 0fdcf2cd..c3be2231 100644 --- a/src/test/javassist/bytecode/StackMapTest.java +++ b/src/test/javassist/bytecode/StackMapTest.java @@ -707,6 +707,78 @@ public class StackMapTest extends TestCase { } } + public void testForHibernate() throws Exception { + ClassFile cf = loader.makeClass("javassist.bytecode.StackMapTestHibTest").getClassFile(); + ConstPool cp = cf.getConstPool(); + MethodInfo mi = new MethodInfo(cp, "foo", "()V"); + Bytecode code = new Bytecode(cp, 0, 0); + code.add(Opcode.RETURN); + CodeAttribute ca = code.toCodeAttribute(); + mi.addAttribute(ca); + cf.addMethod(mi); + + int pc = 111; + int throwableType_index = cp.addClassInfo(Throwable.class.getName()); + + StackMapTable.Writer writer = new StackMapTable.Writer(32); + int[] localTags = { StackMapTable.OBJECT, StackMapTable.OBJECT, StackMapTable.OBJECT, StackMapTable.INTEGER }; + int[] localData = { cp.getThisClassInfo(), cp.addClassInfo("java/lang/Object"), + cp.addClassInfo("[Ljava/lang/Object;"), 0}; + int[] stackTags = { StackMapTable.OBJECT }; + int[] stackData = { throwableType_index }; + writer.fullFrame(pc, localTags, localData, stackTags, stackData); + + ca.setAttribute(writer.toStackMapTable(cp)); + cf.write(new java.io.DataOutputStream(new java.io.FileOutputStream("./test-hibernate.class"))); + } + + public void testCommonSuperclass() throws Exception { + CtClass obj = loader.get("java.lang.Object"); + CtClass objarray = loader.get("java.lang.Object[]"); + + CtClass one = loader.get("byte[]"); + CtClass two = loader.get("byte[][]"); + assertEquals("java.lang.Object", TypeData.commonSuperClassEx(one, two).getName()); + assertTrue(one.subtypeOf(obj)); + assertTrue(two.subtypeOf(obj)); + assertFalse(one.subtypeOf(objarray)); + assertTrue(two.subtypeOf(objarray)); + + one = loader.get("int[][]"); + two = loader.get("java.lang.Object[]"); + assertEquals("java.lang.Object[]", TypeData.commonSuperClassEx(one, two).getName()); + assertTrue(one.subtypeOf(objarray)); + assertTrue(two.subtypeOf(objarray)); + + one = loader.get("int[]"); + two = loader.get("java.lang.String"); + assertEquals("java.lang.Object", TypeData.commonSuperClassEx(one, two).getName()); + assertTrue(one.subtypeOf(obj)); + assertTrue(two.subtypeOf(obj)); + assertFalse(one.subtypeOf(objarray)); + assertFalse(two.subtypeOf(objarray)); + + one = loader.get("int[]"); + two = loader.get("int[]"); + assertEquals("int[]", TypeData.commonSuperClassEx(one, two).getName()); + assertTrue(one.subtypeOf(obj)); + assertFalse(one.subtypeOf(objarray)); + + one = loader.get("int[]"); + two = loader.get("java.lang.String[]"); + assertEquals("java.lang.Object", TypeData.commonSuperClassEx(one, two).getName()); + assertTrue(one.subtypeOf(obj)); + assertTrue(two.subtypeOf(obj)); + assertFalse(one.subtypeOf(objarray)); + assertTrue(two.subtypeOf(objarray)); + + one = loader.get("java.lang.String[]"); + two = loader.get("java.lang.Class[]"); + assertEquals("java.lang.Object[]", TypeData.commonSuperClassEx(one, two).getName()); + assertTrue(one.subtypeOf(objarray)); + assertTrue(two.subtypeOf(objarray)); + } + public void tstCtClassType() throws Exception { ClassPool cp = ClassPool.getDefault(); CtClass cc = cp.get("javassist.CtClassType"); |