1 /* |
1 /* |
2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
38 noSelfSuppression(); |
38 noSelfSuppression(); |
39 basicSupressionTest(); |
39 basicSupressionTest(); |
40 serializationTest(); |
40 serializationTest(); |
41 selfReference(); |
41 selfReference(); |
42 noModification(); |
42 noModification(); |
|
43 initCausePlumbing(); |
43 } |
44 } |
44 |
45 |
45 private static void noSelfSuppression() { |
46 private static void noSelfSuppression() { |
46 Throwable throwable = new Throwable(); |
47 Throwable throwable = new Throwable(); |
47 try { |
48 try { |
48 throwable.addSuppressed(throwable); |
49 throwable.addSuppressed(throwable); |
49 throw new RuntimeException("IllegalArgumentException for self-suppresion not thrown."); |
50 throw new RuntimeException("IllegalArgumentException for self-suppresion not thrown."); |
50 } catch (IllegalArgumentException iae) { |
51 } catch (IllegalArgumentException iae) { |
51 ; // Expected |
52 // Expected to be here |
|
53 if (iae.getCause() != throwable) |
|
54 throw new RuntimeException("Bad cause after self-suppresion."); |
52 } |
55 } |
53 } |
56 } |
54 |
57 |
55 private static void basicSupressionTest() { |
58 private static void basicSupressionTest() { |
56 Throwable throwable = new Throwable(); |
59 Throwable throwable = new Throwable(); |
206 private static class NoSuppression extends Throwable { |
209 private static class NoSuppression extends Throwable { |
207 public NoSuppression(boolean enableSuppression) { |
210 public NoSuppression(boolean enableSuppression) { |
208 super("The medium.", null, enableSuppression, true); |
211 super("The medium.", null, enableSuppression, true); |
209 } |
212 } |
210 } |
213 } |
|
214 |
|
215 private static void initCausePlumbing() { |
|
216 Throwable t1 = new Throwable(); |
|
217 Throwable t2 = new Throwable("message", t1); |
|
218 Throwable t3 = new Throwable(); |
|
219 |
|
220 try { |
|
221 t2.initCause(t3); |
|
222 throw new RuntimeException("Shouldn't reach."); |
|
223 } catch (IllegalStateException ise) { |
|
224 if (ise.getCause() != t2) |
|
225 throw new RuntimeException("Unexpected cause in ISE", ise); |
|
226 Throwable[] suppressed = ise.getSuppressed(); |
|
227 if (suppressed.length != 0) |
|
228 throw new RuntimeException("Bad suppression in ISE", ise); |
|
229 } |
|
230 |
|
231 try { |
|
232 t2.initCause(null); |
|
233 throw new RuntimeException("Shouldn't reach."); |
|
234 } catch (IllegalStateException ise) { |
|
235 ; // Expected; don't want an NPE. |
|
236 } |
|
237 |
|
238 try { |
|
239 t3.initCause(t3); |
|
240 throw new RuntimeException("Shouldn't reach."); |
|
241 } catch (IllegalArgumentException iae) { |
|
242 if (iae.getCause() != t3) |
|
243 throw new RuntimeException("Unexpected cause in ISE", iae); |
|
244 } |
|
245 } |
211 } |
246 } |