aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/Test.java67
-rw-r--r--src/test/javassist/JvstTest5.java15
-rw-r--r--src/test/test/javassist/proxy/ProxySimpleTest.java59
-rw-r--r--src/test/test5/StackmapWithArray83.java38
4 files changed, 157 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/test/javassist/proxy/ProxySimpleTest.java b/src/test/test/javassist/proxy/ProxySimpleTest.java
index f37e7b8c..289895cc 100644
--- a/src/test/test/javassist/proxy/ProxySimpleTest.java
+++ b/src/test/test/javassist/proxy/ProxySimpleTest.java
@@ -140,4 +140,63 @@ public class ProxySimpleTest extends TestCase {
public String extended() { return "ext"; }
public String base2() { return super.base2() + "ext2"; }
}
+
+ String valueDefaultMethods = "";
+
+ public void testDefaultMethods() throws Exception {
+ valueDefaultMethods = "";
+ ProxyFactory f = new ProxyFactory();
+ f.writeDirectory = "./proxy";
+ f.setSuperclass(Default3.class);
+ Class c = f.createClass();
+ MethodHandler mi = new MethodHandler() {
+ public Object invoke(Object self, Method m, Method proceed,
+ Object[] args) throws Throwable {
+ valueDefaultMethods += "1";
+ return proceed.invoke(self, args); // execute the original method.
+ }
+ };
+ Default3 foo = (Default3)c.newInstance();
+ ((Proxy)foo).setHandler(mi);
+ foo.foo();
+ foo.bar();
+ assertEquals("11", valueDefaultMethods);
+ }
+
+ public void testDefaultMethods2() throws Exception {
+ valueDefaultMethods = "";
+ ProxyFactory f = new ProxyFactory();
+ f.writeDirectory = "./proxy";
+ f.setInterfaces(new Class[] { Default2.class });
+ Class c = f.createClass();
+ MethodHandler mi = new MethodHandler() {
+ public Object invoke(Object self, Method m, Method proceed,
+ Object[] args) throws Throwable {
+ valueDefaultMethods += "1";
+ return proceed.invoke(self, args); // execute the original method.
+ }
+ };
+ Default2 foo = (Default2)c.newInstance();
+ ((Proxy)foo).setHandler(mi);
+ foo.foo();
+ foo.bar();
+ assertEquals("11", valueDefaultMethods);
+ }
+
+ public static interface Default1 {
+ default int foo() { return 0; }
+ default int baz() { return 2; }
+ }
+
+ public static interface Default2 extends Default1 {
+ default int bar() { return 1; }
+ }
+
+ public static class Default3 implements Default2 {
+ public int foo() { return Default2.super.foo(); }
+ }
+
+ public static class Default4 extends Default3 {
+ public int baz() { return super.baz(); }
+ }
}
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;
+ }
+ }
+}