diff options
author | chibash <chiba@javassist.org> | 2016-07-30 16:22:59 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2016-07-30 16:22:59 +0900 |
commit | 7ec83a2e3d3c5f820ee1756d5c7510acf8671d4b (patch) | |
tree | 870a8b02f91bd5f481baacb74d83f1898627c75f /src/test | |
parent | 5e4572a90f9a11618f5a076ae573932b71a7e13e (diff) | |
download | javassist-7ec83a2e3d3c5f820ee1756d5c7510acf8671d4b.tar.gz javassist-7ec83a2e3d3c5f820ee1756d5c7510acf8671d4b.zip |
fixes a bug of stackmap generation. The bug was reported here: https://github.com/jboss-javassist/javassist/issues/83
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/Test.java | 67 | ||||
-rw-r--r-- | src/test/javassist/JvstTest5.java | 15 | ||||
-rw-r--r-- | src/test/test5/StackmapWithArray83.java | 38 |
3 files changed, 98 insertions, 22 deletions
diff --git a/src/test/Test.java b/src/test/Test.java index 2e6f5c3d..c21d930f 100644 --- a/src/test/Test.java +++ b/src/test/Test.java @@ -1,31 +1,54 @@ +import java.util.ArrayList; +import java.util.List; import javassist.*; -import javassist.bytecode.*; -import javassist.bytecode.annotation.*; -@interface Entity {} +class InvalidStackMapFrame { -@interface Table { String[] textValues() default {}; } + public void bytecodeVerifyError1() { + String[] newLine = new String[10]; + for (int i = 0; i < 5; i++) { + String a = newLine[1]; + newLine[4] = a; + } + } + + public void bytecodeVerifyError() { + // javassist bug : invalid stack map frame + List<Integer> test = new ArrayList<Integer>(); + String[] newLine = new String[10]; + for (Integer idx : test) { + // invalid stackMapFrame + // FRAME FULL [bug_regression_jdk7/javassist/InvalidStackMapFrame java/util/ArrayList java/lang/Object java/util/Iterator T T T I] [] + // java/lang/Object is wrong -> [Ljava/lang/String; is correct + String address = newLine[1]; + int tabPos = -1; + if (tabPos != -1) { + address = address.substring(tabPos + 1); + } + newLine[4] = address; + } + + } +} public class Test { + private static final String INVALID_STACK_MAP_FRAME = "InvalidStackMapFrame"; + public static void main(String[] args) throws Exception { + + // CustomURLClassLoader classLoader = new CustomURLClassLoader(new URL[]{}, Thread.currentThread().getContextClassLoader()); + ClassPool classPool = ClassPool.getDefault(); - ClassFile cf = classPool.makeClass("TestSub").getClassFile(); - ConstPool constPool = cf.getConstPool(); - Annotation[] annotations = new Annotation[2]; - AnnotationsAttribute attrib = - new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag); - Annotation annotation = new Annotation(constPool, classPool.get("Entity")); - annotations[0] = annotation; - // Add @Table(name="",schema="") to class - annotation = new Annotation(constPool, classPool.get("Table")); - annotation.addMemberValue("name", new StringMemberValue("name", constPool)); - annotation.addMemberValue("schema", new StringMemberValue("schema", constPool)); -// ArrayMemberValue blankMemberValueArray = new ArrayMemberValue(new AnnotationMemberValue(constPool), constPool); -// blankMemberValueArray.setValue(new MemberValue[0]); -// annotation.addMemberValue("textValues", blankMemberValueArray); - annotations[1] = annotation; - attrib.setAnnotations(annotations); - cf.addAttribute(attrib); - System.out.println("done"); + // classPool.appendClassPath(new LoaderClassPath(classLoader)); + + final CtClass ctClass = classPool.get(INVALID_STACK_MAP_FRAME); + final CtMethod method = ctClass.getDeclaredMethod("bytecodeVerifyError"); + method.addLocalVariable("test_localVariable", CtClass.intType); + method.insertBefore("{ test_localVariable = 1; }"); + ctClass.debugWriteFile(); + Class<?> cc = ctClass.toClass(); + System.out.println(cc.getName()); + InvalidStackMapFrame obj = (InvalidStackMapFrame)cc.newInstance(); + obj.bytecodeVerifyError(); } } diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 1af027fd..792fed6e 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -220,4 +220,19 @@ public class JvstTest5 extends JvstTestRoot { Class clazzz = badClass.toClass(); Object obj = clazzz.newInstance(); // <-- falls here } + + public void test83StackmapWithArrayType() throws Exception { + final CtClass ctClass = sloader.get("test5.StackmapWithArray83"); + final CtMethod method = ctClass.getDeclaredMethod("bytecodeVerifyError"); + method.addLocalVariable("test_localVariable", CtClass.intType); + method.insertBefore("{ test_localVariable = 1; }"); + + final CtMethod method2 = ctClass.getDeclaredMethod("bytecodeVerifyError2"); + method2.addLocalVariable("test_localVariable", CtClass.intType); + method2.insertBefore("{ test_localVariable = 1; }"); + + ctClass.writeFile(); + Object obj = make(ctClass.getName()); + assertEquals(1, invoke(obj, "run")); + } } diff --git a/src/test/test5/StackmapWithArray83.java b/src/test/test5/StackmapWithArray83.java new file mode 100644 index 00000000..c8333d81 --- /dev/null +++ b/src/test/test5/StackmapWithArray83.java @@ -0,0 +1,38 @@ +package test5; + +import java.util.ArrayList; +import java.util.List; + +public class StackmapWithArray83 { + public int run() { + bytecodeVerifyError(); + bytecodeVerifyError2(); + return 1; + } + + public void bytecodeVerifyError() { + List<Integer> test = new ArrayList<Integer>(); + String[] newLine = new String[10]; + for (Integer idx : test) { + String address = newLine[1]; + int tabPos = -1; + if (tabPos != -1) { + address = address.substring(tabPos + 1); + } + newLine[4] = address; + } + } + + public void bytecodeVerifyError2() { + List<Integer> test = new ArrayList<Integer>(); + int[] newLine = new int[10]; + for (Integer idx : test) { + int address = newLine[1]; + int tabPos = -1; + if (tabPos != -1) { + address = address + tabPos; + } + newLine[4] = address; + } + } +} |