1 package test5; 2 3 import java.util.Random; 4 import javassist.*; 5 6 public class JIRA241 { run()7 public int run() { 8 test(this); 9 return 10; 10 } 11 test(Object o)12 public static void test(Object o) { 13 //part 1 14 if (o == null) { 15 return; 16 } 17 18 //part 2 19 int oper = new Random().nextInt(); 20 switch (oper) { 21 case 1: 22 break; 23 } 24 } 25 main(String[] args)26 public static void main(String[] args) throws Exception { 27 ClassPool pool = ClassPool.getDefault(); 28 CtClass cc = pool.get("test5.JIRA241"); 29 CtMethod testMethod = cc.getMethod("test", "(Ljava/lang/Object;)V"); 30 testMethod.insertAfter("System.out.println(\"inserted!\");"); 31 cc.writeFile(); 32 } 33 } 34