2 final static int INDEX1 = 0xcafebabe;
3 final static int INDEX2 = 0xbabecafe;
4 final static int INDEX3 = 0xdeadbeef;
6 static boolean printStackTrace;
8 public static void main(String[] argv) {
9 printStackTrace = true;
11 // if (argv.length > 0)
12 // if (argv[0].equals("stacktrace"))
13 // printStackTrace = true;
15 boolean catched = false;
17 pln("---------- normal exceptions --------------------");
20 p("throw new Exception():");
21 throw new Exception();
22 } catch (Exception e) {
28 /* check if catch block was executed */
35 p("throw new Exception() (from subroutines):");
38 } catch (Exception e) {
44 p("NullPointerException:");
48 } catch (NullPointerException e) {
56 pln("---------- test soft inline exceptions ----------");
57 pln("/* thrown twice to check the inline jump code */");
60 p("ArithmeticException (only w/ -softnull):");
61 int i = 1, j = 0, k = i / j;
63 } catch (ArithmeticException e) {
64 String msg = e.getMessage();
66 if (msg == null || !msg.equals("/ by zero")) {
67 pln("FAILED: wrong message: " + msg + ", should be: / by zero");
76 p("ArithmeticException (only w/ -softnull):");
77 long i = 1, j = 0, k = i / j;
79 } catch (ArithmeticException e) {
80 String msg = e.getMessage();
82 if (msg == null || !msg.equals("/ by zero")) {
83 pln("FAILED: wrong message: " + msg + ", should be: / by zero");
93 p("ArrayIndexOutOfBoundsException:");
94 int[] ia = new int[1];
97 } catch (ArrayIndexOutOfBoundsException e) {
98 String msg = e.getMessage();
100 if (msg == null || !msg.equals(String.valueOf(INDEX1))) {
101 pln("FAILED: wrong index: " + msg + ", should be: " + INDEX1);
110 p("ArrayIndexOutOfBoundsException:");
111 int[] ia = new int[1];
114 } catch (ArrayIndexOutOfBoundsException e) {
115 String msg = e.getMessage();
117 if (msg == null || !msg.equals(String.valueOf(INDEX2))) {
118 pln("FAILED: wrong index: " + msg + ", should be: " + INDEX2);
129 p("ArrayStoreException:");
130 Integer[] ia = new Integer[1];
131 Object[] oa = (Object[]) ia;
132 oa[0] = new Object();
134 } catch (ArrayStoreException e) {
140 p("ArrayStoreException:");
141 Integer[] ia = new Integer[1];
142 Object[] oa = (Object[]) ia;
143 oa[0] = new Object();
145 } catch (ArrayStoreException e) {
152 p("ClassCastException:");
153 Object o = new Object();
154 Integer i = (Integer) o;
156 } catch (ClassCastException e) {
162 p("ClassCastException:");
163 Object o = new Object();
167 } catch (ClassCastException e) {
174 p("NegativeArraySizeException:");
175 int[] ia = new int[-1];
177 } catch (NegativeArraySizeException e) {
183 p("NegativeArraySizeException:");
184 int[] ia = new int[-1];
186 } catch (NegativeArraySizeException e) {
193 p("NullPointerException (only w/ -softnull):");
197 } catch (NullPointerException e) {
203 p("NullPointerException (only w/ -softnull):");
207 } catch (NullPointerException e) {
213 p("OutOfMemoryError:");
214 /* 100 MB should be enough */
215 byte[] ba = new byte[100 * 1024 * 1024];
217 } catch (OutOfMemoryError e) {
223 p("OutOfMemoryError:");
224 /* 100 MB should be enough */
225 byte[] ba = new byte[100 * 1024 * 1024];
227 } catch (OutOfMemoryError e) {
235 pln("---------- exceptions in leaf functions ---------");
238 p("ArithmeticException:");
241 } catch (ArithmeticException e) {
247 p("ArrayIndexOutOfBoundsException:");
248 aioobesub(new int[1]);
250 } catch (ArrayIndexOutOfBoundsException e) {
251 String msg = e.getMessage();
253 if (msg == null || !msg.equals(String.valueOf(INDEX3))) {
254 pln("FAILED: wrong index: " + msg + ", should be: " + INDEX3);
264 p("ClassCastException:");
265 ccesub(new Object(), new Integer(0));
267 } catch (ClassCastException e) {
273 p("NullPointerException:");
276 } catch (NullPointerException e) {
284 pln("---------- some asmpart exceptions --------------");
287 p("NullPointerException in <clinit> (PUTSTATIC):");
288 extest_clinit_1.i = 1;
290 } catch (ExceptionInInitializerError e) {
291 if (e.getCause().getClass() != NullPointerException.class) {
300 p("NullPointerException in <clinit> (GETSTATIC):");
301 int i = extest_clinit_2.i;
303 } catch (ExceptionInInitializerError e) {
304 if (e.getCause().getClass() != NullPointerException.class) {
315 pln("---------- exception related things -------------");
318 p("load/link an exception class in asmpart:");
319 throw new Exception();
320 } catch (UnknownError e) {
321 /* this exception class MUST NOT be loaded before!!!
322 otherwise this test in useless */
323 } catch (Exception e) {
331 pln("---------- native stub exceptions ---------------");
334 p("NullPointerException (native):");
335 System.arraycopy(null, 1, null, 1, 1);
337 } catch (Exception e) {
343 p("NullPointerException in <clinit>:");
344 extest_clinit_3.sub();
346 } catch (ExceptionInInitializerError e) {
349 } catch (UnsatisfiedLinkError e) {
350 /* catch this one for staticvm and say it's ok */
357 p("UnsatisfiedLinkError:");
360 } catch (UnsatisfiedLinkError e) {
369 pln("---------- no OK beyond this point --------------");
371 pln("NullPointerException (without catch):");
377 synchronized static void sub() throws Exception {
381 static void sub2() throws Exception {
385 synchronized static void sub3() throws Exception {
389 static void sub4() throws Exception {
390 throw new Exception();
393 static void aesub(int a, int b) {
397 static void aioobesub(int[] ia) {
401 static void ccesub(Object o, Integer i) {
405 static void npesub(int[] ia) {
409 static native void nsub();
411 static void p(String s) {
413 for (int i = s.length(); i < 46; i++) {
414 System.out.print(" ");
419 System.out.println();
422 static void pln(String s) {
423 System.out.println(s);
430 static void failed() {
434 static void pstacktrace(Throwable e) {
435 if (!printStackTrace)
438 System.out.println();
442 public class extest_clinit_1 {
451 public class extest_clinit_2 {
460 public class extest_clinit_3 {
466 public static native void sub();