|
Last change
on this file since 3103 was 1392, checked in by bird, 22 years ago |
|
This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.
|
-
Property cvs2svn:cvs-rev
set to
1.1.1.2
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 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 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.