OSDN Git Service

2007-03-19 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / testsuite / libjava.lang / Array_3.java
1 // Test to make sure null arrays throw the right execption
2
3 public class Array_3
4 {
5   static Object foo ()
6   {
7     return null;
8   }
9
10   static int[] bar ()
11   {
12     return null;
13   }
14
15   static int baz ()
16   {
17     int[] x = (int[])null;
18     int nn = x.length;
19     return 5;
20   }
21
22   public static void main(String args[])
23   {
24     boolean ok = false;
25     int nn = 0;
26
27     try
28       {
29         int[] x = (int[])foo();
30         nn = x.length;
31       }
32     catch (NullPointerException _)
33       {
34         ok = true;
35       }
36     if (!ok)
37       throw new RuntimeException("test failed:1");
38
39     ok = false;
40     try
41       {
42         int[] x = bar();
43         nn = x.length;
44       }
45     catch (NullPointerException _)
46       {
47         ok = true;
48       }
49     if (!ok)
50       throw new RuntimeException("test failed:2");
51
52     ok = false;
53     try
54       {
55         int[] x = bar();
56         nn = x[0];
57       }
58     catch (NullPointerException _)
59       {
60         ok = true;
61       }
62
63     if (!ok || nn != 0)
64       throw new RuntimeException("test failed:3");
65
66     ok = false;
67     try
68       {
69         int[] x = (int[])null;
70         nn = x.length;
71       }
72     catch (NullPointerException _)
73       {
74         ok = true;
75       }
76     if (!ok)
77       throw new RuntimeException("test failed:4");
78
79     ok = false;
80     try
81       {
82         nn = baz ();
83       }
84     catch (NullPointerException _)
85       {
86         ok = true;
87       }
88     if (!ok)
89       throw new RuntimeException("test failed:5");
90   }
91 }