mirror of
git://gcc.gnu.org/git/gcc.git
synced 2024-12-28 11:55:21 +08:00
4d00945e45
2002-03-28 Andrew Haley <aph@redhat.com> * libjava.lang/Throw_2.java: New. * libjava.lang/Throw_2.out: New. From-SVN: r51515
58 lines
1.4 KiB
Java
58 lines
1.4 KiB
Java
// Check that NullPointerExceptions thrown from library code are
|
|
// caught. This detects a number of failures that can be caused by
|
|
// libgcj being built incorrectly. In particular, we ensure that a
|
|
// SEGV in native (i.e. C++) code in libgcj is handled correctly.
|
|
|
|
// Regrettably, we cannot guarantee that Double.parseDouble() will
|
|
// always be native code, or that it will never be inlined. It could
|
|
// be argued that we should add a method to libgcj that will be
|
|
// guaranteed forever to be native, but I'm reluctant to add to the
|
|
// library for the sole purpose of performing this test.
|
|
|
|
public class Throw_2
|
|
{
|
|
public static Throwable obj()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public static String str()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
static double d;
|
|
|
|
public static void main (String[] args)
|
|
{
|
|
// This NullPointerException will, at the time of writing, be
|
|
// thrown from Java code in libgcj.
|
|
try
|
|
{
|
|
java.util.Vector v = new java.util.Vector (null);
|
|
System.out.println ("fail: no exception thrown");
|
|
}
|
|
catch (NullPointerException _)
|
|
{
|
|
}
|
|
catch (Throwable _)
|
|
{
|
|
System.out.println ("fail: " + _);
|
|
}
|
|
// This one will, at the time of writing, be thrown from C++
|
|
// code in libgcj.
|
|
try
|
|
{
|
|
d = Double.parseDouble(str());
|
|
System.out.println ("fail: no exception thrown");
|
|
}
|
|
catch (NullPointerException _)
|
|
{
|
|
}
|
|
catch (Throwable _)
|
|
{
|
|
System.out.println ("fail: " + _);
|
|
}
|
|
}
|
|
}
|