summaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.lang/Array_3.java
blob: e94549a0f4ebddaab346ad133a6bde88ed4404e5 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Test to make sure null arrays throw the right execption

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

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

  static int baz ()
  {
    int[] x = (int[])null;
    int nn = x.length;
    return 5;
  }

  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");

    ok = false;
    try
      {
	nn = baz ();
      }
    catch (NullPointerException _)
      {
	ok = true;
      }
    if (!ok)
      throw new RuntimeException("test failed:5");
  }
}