1 // Check that NullPointerExceptions thrown from library code are
2 // caught.  This detects a number of failures that can be caused by
3 // libgcj being built incorrectly.  In particular, we ensure that a
4 // SEGV in native (i.e. C++) code in libgcj is handled correctly.
5 
6 // Regrettably, we cannot guarantee that Double.parseDouble() will
7 // always be native code, or that it will never be inlined.  It could
8 // be argued that we should add a method to libgcj that will be
9 // guaranteed forever to be native, but I'm reluctant to add to the
10 // library for the sole purpose of performing this test.
11 
12 public class Throw_2
13 {
obj()14   public static Throwable obj()
15     {
16       return null;
17     }
18 
str()19   public static String str()
20     {
21       return null;
22     }
23 
24   static double d;
25 
main(String[] args)26   public static void main (String[] args)
27     {
28       // This NullPointerException will, at the time of writing, be
29       // thrown from Java code in libgcj.
30       try
31 	{
32 	  java.util.Vector v = new java.util.Vector (null);
33 	  System.out.println ("fail: no exception thrown");
34 	}
35       catch (NullPointerException _)
36 	{
37 	  System.out.println ("1");
38 	}
39       catch (Throwable _)
40 	{
41 	  System.out.println ("fail: " + _);
42 	}
43       // This one will, at the time of writing, be thrown from C++
44       // code in libgcj.
45       try
46 	{
47 	  d = Double.parseDouble(str());
48 	  System.out.println ("fail: no exception thrown");
49 	}
50       catch (NullPointerException _)
51 	{
52 	  System.out.println ("2");
53 	}
54       catch (Throwable _)
55 	{
56 	  System.out.println ("fail: " + _);
57 	}
58     }
59 }
60