source: trunk/src/gcc/libjava/testsuite/libjava.lang/Throw_2.java@ 141

Last change on this file since 141 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.4 KB
Line 
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
12public class Throw_2
13{
14 public static Throwable obj()
15 {
16 return null;
17 }
18
19 public static String str()
20 {
21 return null;
22 }
23
24 static double d;
25
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 }
38 catch (Throwable _)
39 {
40 System.out.println ("fail: " + _);
41 }
42 // This one will, at the time of writing, be thrown from C++
43 // code in libgcj.
44 try
45 {
46 d = Double.parseDouble(str());
47 System.out.println ("fail: no exception thrown");
48 }
49 catch (NullPointerException _)
50 {
51 }
52 catch (Throwable _)
53 {
54 System.out.println ("fail: " + _);
55 }
56 }
57}
Note: See TracBrowser for help on using the repository browser.