aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/Test.java
blob: c21d930f1094b028738e41e248ee3df90fd7c1fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.ArrayList;
import java.util.List;
import javassist.*;

class InvalidStackMapFrame {

	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();
        // 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();
    }
}