KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > T15111rs2


1
2
3 /*
4   this test will fail because it contains a checkcast / pop in order
5   to make it pass we would need to treat checkcast as an operation
6   with side effects. well written programs would intiontionaly casue
7   a cast exception, and checking for them will make our output less
8   obscure, so we'll leave it as it is. */

9
10 class T15111rs2 {
11     static int i = 0;
12     static T15111rs2 a() { throw new RuntimeException JavaDoc(); }
13     static T15111rs2 t = null;
14     T15111rs2 t1 = null;
15
16     T15111rs2() {}
17     T15111rs2(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.i++; // instance field access
26
} catch (NullPointerException JavaDoc e) {
27         System.out.print("1 ");
28     }
29     T15111rs2[] ta = {};
30     try {
31         ta[0].i++; // array access
32
} catch (ArrayIndexOutOfBoundsException JavaDoc e) {
33         System.out.print("2 ");
34     }
35     try {
36         a().i++; // method call
37
} catch (RuntimeException JavaDoc e) {
38         System.out.print("3 ");
39     }
40     Object JavaDoc o = "";
41     try {
42         ((T15111rs2)o).i++; // unsafe cast
43
} catch (ClassCastException JavaDoc e) {
44         System.out.print("4 ");
45     }
46     try {
47         new T15111rs2(1).i++; // constructor
48
} catch (IllegalArgumentException JavaDoc e) {
49         System.out.print("5");
50     }
51     if (i != 0) System.out.print("Oops ");
52     }
53 }
54     
55
Popular Tags