PR rtl-optimization/57003
[official-gcc.git] / libjava / testsuite / libjava.lang / StackTrace2.java
blob01c7d5bac7ff35aa5c65cf436b3d932c75fd25e9
1 // Check that stack trace's work, and stack trace line numbers, if available,
2 // are correct.
4 public class StackTrace2
6 public static void main(String[] args)
7 {
8 try
10 new StackTrace2().a();
12 catch (Exception x)
14 StackTraceElement[] trace = x.getStackTrace();
15 checkTrace(trace);
19 void a()
21 new Inner().foo();
24 class Inner
26 public void foo()
28 doCrash(null);
31 public void doCrash(Object o)
33 o.toString();
37 static void checkTrace(StackTraceElement[] trace)
39 System.out.println("Trace length = " + trace.length);
40 checkLine(trace[0], "StackTrace2$Inner", "doCrash", 33);
41 checkLine(trace[1], "StackTrace2$Inner", "foo", 28);
42 checkLine(trace[2], "StackTrace2", "a", 21);
43 checkLine(trace[3], "StackTrace2", "main", 10);
46 static void checkLine(StackTraceElement frame, String expected_cl,
47 String expected_method, int expected_line)
49 if (frame.getClassName().equals(expected_cl))
50 System.out.print(expected_cl);
51 else
52 System.out.print("FAIL - expected " + expected_cl + ", got: " +
53 frame.getClassName());
55 System.out.print(".");
57 if (frame.getMethodName().equals(expected_method))
58 System.out.print(expected_method);
59 else
60 System.out.print("FAIL - expected " + expected_method + ", got: " +
61 frame.getMethodName());
63 System.out.print(":");
65 // Permit either the correct line number or no line number. This is so
66 // we don't fail on platforms that don't yet support reading debug info
67 // for stack traces, or when no debug info is available.
68 if (frame.getLineNumber() < 0
69 || (frame.getLineNumber() == expected_line
70 && frame.getFileName().equals("StackTrace2.java")))
71 System.out.println("OK");
72 else
73 System.out.println("FAIL - expected " + expected_line + ", got: "
74 + frame.getLineNumber() + ", in file "
75 + frame.getFileName());