diff options
Diffstat (limited to 'src/test/Test.java')
-rw-r--r-- | src/test/Test.java | 67 |
1 files changed, 45 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(); } } |