aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/test5/JIRA241.java
blob: e6f8e9574619843ea1217fd7cf017e25a1e14d38 (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
package test5;

import java.util.Random;
import javassist.*;

public class JIRA241 {
    public int run() {
        test(this);
        return 10;
    }

    public static void test(Object o) {
        //part 1
        if (o == null) {
            return;
        }
 
        //part 2
        int oper = new Random().nextInt();
        switch (oper) {
        case 1:
            break;
        }
    }

    public static void main(String[] args) throws Exception {
        ClassPool pool  = ClassPool.getDefault();
        CtClass cc = pool.get("test5.JIRA241");
        CtMethod testMethod = cc.getMethod("test", "(Ljava/lang/Object;)V");
        testMethod.insertAfter("System.out.println(\"inserted!\");");
        cc.writeFile();
    }
}