aboutsummaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.lang/Array_3.java
blob: 453387d51fbfac3d48ae436f7a56a71e0692350d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Test to make sure null arrays throw the right execption

public class Array_3
{
  static Object foo ()
  {
    return null;
  }

  static int[] bar ()
  {
    return null;
  }

  public static void main(String args[])
  {
    boolean ok = false;
    int nn = 0;

    try
      {
	int[] x = (int[])foo();
	nn = x.length;
      }
    catch (NullPointerException _)
      {
	ok = true;
      }
    if (!ok)
      throw new RuntimeException("test failed:1");

    ok = false;
    try
      {
	int[] x = bar();
	nn = x.length;
      }
    catch (NullPointerException _)
      {
	ok = true;
      }
    if (!ok)
      throw new RuntimeException("test failed:2");

    ok = false;
    try
      {
	int[] x = bar();
	nn = x[0];
      }
    catch (NullPointerException _)
      {
	ok = true;
      }

    if (!ok || nn != 0)
      throw new RuntimeException("test failed:3");

    ok = false;
    try
      {
	int[] x = (int[])null;
	nn = x.length;
      }
    catch (NullPointerException _)
      {
	ok = true;
      }
    if (!ok)
      throw new RuntimeException("test failed:4");
  }
}