test/java/lang/Throwable/SuppressedExceptions.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 24,34 ****
import java.io.*;
import java.util.*;
/*
* @test
! * @bug 6911258 6962571 6963622 6991528 7005628
* @summary Basic tests of suppressed exceptions
* @author Joseph D. Darcy
*/
public class SuppressedExceptions {
--- 24,34 ----
import java.io.*;
import java.util.*;
/*
* @test
! * @bug 6911258 6962571 6963622 6991528 7005628 8012044
* @summary Basic tests of suppressed exceptions
* @author Joseph D. Darcy
*/
public class SuppressedExceptions {
*** 38,56 ****
noSelfSuppression();
basicSupressionTest();
serializationTest();
selfReference();
noModification();
}
private static void noSelfSuppression() {
Throwable throwable = new Throwable();
try {
throwable.addSuppressed(throwable);
throw new RuntimeException("IllegalArgumentException for self-suppresion not thrown.");
} catch (IllegalArgumentException iae) {
! ; // Expected
}
}
private static void basicSupressionTest() {
Throwable throwable = new Throwable();
--- 38,59 ----
noSelfSuppression();
basicSupressionTest();
serializationTest();
selfReference();
noModification();
+ initCausePlumbing();
}
private static void noSelfSuppression() {
Throwable throwable = new Throwable();
try {
throwable.addSuppressed(throwable);
throw new RuntimeException("IllegalArgumentException for self-suppresion not thrown.");
} catch (IllegalArgumentException iae) {
! // Expected to be here
! if (iae.getCause() != throwable)
! throw new RuntimeException("Bad cause after self-suppresion.");
}
}
private static void basicSupressionTest() {
Throwable throwable = new Throwable();
*** 206,211 ****
--- 209,246 ----
private static class NoSuppression extends Throwable {
public NoSuppression(boolean enableSuppression) {
super("The medium.", null, enableSuppression, true);
}
}
+
+ private static void initCausePlumbing() {
+ Throwable t1 = new Throwable();
+ Throwable t2 = new Throwable("message", t1);
+ Throwable t3 = new Throwable();
+
+ try {
+ t2.initCause(t3);
+ throw new RuntimeException("Shouldn't reach.");
+ } catch (IllegalStateException ise) {
+ if (ise.getCause() != t2)
+ throw new RuntimeException("Unexpected cause in ISE", ise);
+ Throwable[] suppressed = ise.getSuppressed();
+ if (suppressed.length != 0)
+ throw new RuntimeException("Bad suppression in ISE", ise);
+ }
+
+ try {
+ t2.initCause(null);
+ throw new RuntimeException("Shouldn't reach.");
+ } catch (IllegalStateException ise) {
+ ; // Expected; don't want an NPE.
+ }
+
+ try {
+ t3.initCause(t3);
+ throw new RuntimeException("Shouldn't reach.");
+ } catch (IllegalArgumentException iae) {
+ if (iae.getCause() != t3)
+ throw new RuntimeException("Unexpected cause in ISE", iae);
+ }
+ }
}