KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > T151241rs2


1
2
3 /* this will fail becasue it depends on the side effects of an array
4    load. We do not consider an array load to have side effects so we
5    optimize these out because their values are not used
6 */

7
8
9 class T151241rs2 {
10     static int i = 0;
11     static T151241rs2 a() { throw new RuntimeException JavaDoc(); }
12     static void b(int i) { System.out.print("Oops "); }
13     static T151241rs2 t = null;
14     T151241rs2 t1 = null;
15
16     T151241rs2() {}
17     T151241rs2(int i) { throw new IllegalArgumentException JavaDoc(); }
18     public String JavaDoc toString() {
19     int i = 0;
20     i /= i; // throw ArithmeticException, rather than return
21
return null;
22     }
23     public static void main(String JavaDoc[] args) {
24     try {
25         t.t1.b(i++); // instance field access
26
} catch (NullPointerException JavaDoc e) {
27         System.out.print("1 ");
28     }
29     T151241rs2[] ta = {};
30     try {
31         ta[0].b(i++); // array access
32
} catch (ArrayIndexOutOfBoundsException JavaDoc e) {
33         System.out.print("2 ");
34     }
35     try {
36         a().b(i++); // method call
37
} catch (RuntimeException JavaDoc e) {
38         System.out.print("3 ");
39     }
40     Object JavaDoc o = "";
41     try {
42         ((T151241rs2)o).b(i++); // unsafe cast
43
} catch (ClassCastException JavaDoc e) {
44         System.out.print("4 ");
45     }
46     try {
47         ("" + new T151241rs2()).valueOf(1); // abrupt binary expression
48
System.out.print("Oops ");
49     } catch (ArithmeticException JavaDoc e) {
50         System.out.print("5 ");
51     }
52     try {
53         new T151241rs2(1).b(i++); // constructor
54
} catch (IllegalArgumentException JavaDoc e) {
55         System.out.print("6");
56     }
57     if (i != 0) System.out.print("Oops ");
58     }
59 }
60     
61
Popular Tags