GNU header update.
[cacao.git] / tests / kaffe / NullInvoke.java
1 /**
2  * Test case for PR#625.
3  *
4  * Submitted by Feng Qian <fqian@sable.mcgill.ca>.
5  * Different implementation by Edouard G. Parmelan <egp@free.fr>
6  */
7 public class NullInvoke {
8     public static class InvokeSpecial {
9         private String getName() {
10             return "InvokeSpecial";
11         }
12
13         public void printName(InvokeSpecial obj) {
14             String s = obj.getName();   // invokespecial with null
15             System.out.println(s);
16         }
17     }
18
19     public static class InvokeVirtual {
20         public String getName() {
21             return "InvokeVirtual";
22         }
23
24         public void printName(InvokeVirtual obj) {
25             String s = obj.getName();   // invokevirtual with null
26             System.out.println(s);
27         }
28     }
29
30     public static class InvokeFinalVirtual {
31         public final String getName() {
32             return "InvokeFinalVirtual";
33         }
34
35         public void printName(final InvokeFinalVirtual obj) {
36             String s = obj.getName();   // invokespecial with null
37             System.out.println(s);
38         }
39     }
40
41     public static interface Interface {
42         public String getName();
43     }
44
45     public static class InvokeInterface
46         implements Interface
47     {
48         public String getName() {
49             return "InvokeInterface";
50         }
51
52         public void printName(Interface obj) {
53             String s = obj.getName();   // invokeinterface with null
54             System.out.println(s);
55         }
56     }
57
58     public static void main (String[] args) {
59         try {
60             new InvokeSpecial().printName(null);
61             System.out.println ("FAIL");
62         }
63         catch (NullPointerException npe) {
64             System.out.println ("PASS");
65         }
66
67         try {
68             new InvokeVirtual().printName(null);
69             System.out.println ("FAIL");
70         }
71         catch (NullPointerException npe) {
72             System.out.println ("PASS");
73         }
74
75         try {
76             new InvokeFinalVirtual().printName(null);
77             System.out.println ("FAIL");
78         }
79         catch (NullPointerException npe) {
80             System.out.println ("PASS");
81         }
82
83         try {
84             new InvokeInterface().printName(null);
85             System.out.println ("FAIL");
86         }
87         catch (NullPointerException npe) {
88             System.out.println ("PASS");
89         }
90     }
91 }
92
93 /* Expected Output:
94 PASS
95 PASS
96 PASS
97 PASS
98 */