2001-12-20 22:09:03 +08:00
|
|
|
// Test to make sure null arrays throw the right execption
|
|
|
|
|
|
|
|
public class Array_3
|
|
|
|
{
|
|
|
|
static Object foo ()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int[] bar ()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2002-10-03 21:12:01 +08:00
|
|
|
static int baz ()
|
|
|
|
{
|
|
|
|
int[] x = (int[])null;
|
|
|
|
int nn = x.length;
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2001-12-20 22:09:03 +08:00
|
|
|
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)
|
2002-07-03 01:21:10 +08:00
|
|
|
throw new RuntimeException("test failed:1");
|
2001-12-20 22:09:03 +08:00
|
|
|
|
|
|
|
ok = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int[] x = bar();
|
|
|
|
nn = x.length;
|
|
|
|
}
|
|
|
|
catch (NullPointerException _)
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
if (!ok)
|
2002-07-03 01:21:10 +08:00
|
|
|
throw new RuntimeException("test failed:2");
|
2001-12-20 22:09:03 +08:00
|
|
|
|
|
|
|
ok = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int[] x = bar();
|
|
|
|
nn = x[0];
|
|
|
|
}
|
|
|
|
catch (NullPointerException _)
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok || nn != 0)
|
2002-07-03 01:21:10 +08:00
|
|
|
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");
|
2002-10-03 21:12:01 +08:00
|
|
|
|
|
|
|
ok = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
nn = baz ();
|
|
|
|
}
|
|
|
|
catch (NullPointerException _)
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
throw new RuntimeException("test failed:5");
|
2001-12-20 22:09:03 +08:00
|
|
|
}
|
|
|
|
}
|