darcy@622: /* darcy@622: * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. darcy@622: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. darcy@622: * darcy@622: * This code is free software; you can redistribute it and/or modify it darcy@622: * under the terms of the GNU General Public License version 2 only, as darcy@622: * published by the Free Software Foundation. darcy@622: * darcy@622: * This code is distributed in the hope that it will be useful, but WITHOUT darcy@622: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or darcy@622: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License darcy@622: * version 2 for more details (a copy is included in the LICENSE file that darcy@622: * accompanied this code). darcy@622: * darcy@622: * You should have received a copy of the GNU General Public License version darcy@622: * 2 along with this work; if not, write to the Free Software Foundation, darcy@622: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. darcy@622: * darcy@622: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA darcy@622: * or visit www.oracle.com if you need additional information or have any darcy@622: * questions. darcy@622: */ darcy@622: darcy@622: /* darcy@622: * @test darcy@622: * @bug 6971877 darcy@622: * @author Joseph D. Darcy darcy@622: * @summary Verify a primary exception suppresses all throwables darcy@622: */ darcy@622: darcy@622: public class TwrSuppression implements AutoCloseable { darcy@622: public static void main(String... args) throws Throwable { darcy@622: try { darcy@622: try (TwrSuppression r1 = new TwrSuppression(false); darcy@622: TwrSuppression r2 = new TwrSuppression(true)) { darcy@622: throw new RuntimeException(); darcy@622: } darcy@622: } catch(RuntimeException e) { darcy@622: Throwable[] suppressedExceptions = e.getSuppressedExceptions(); darcy@622: int length = suppressedExceptions.length; darcy@622: if (length != 2) darcy@622: throw new RuntimeException("Unexpected length " + length); darcy@622: darcy@622: if (suppressedExceptions[0].getClass() != Error.class || darcy@622: suppressedExceptions[1].getClass() != Exception.class) { darcy@622: System.err.println("Unexpected suppressed types!"); darcy@622: e.printStackTrace(); darcy@622: throw new RuntimeException(e); darcy@622: } darcy@622: } darcy@622: } darcy@622: darcy@622: private boolean throwError; darcy@622: darcy@622: private TwrSuppression(boolean throwError) { darcy@622: this.throwError = throwError; darcy@622: } darcy@622: darcy@622: @Override darcy@622: public void close() throws Exception { darcy@622: if (throwError) { darcy@622: throw new Error(); darcy@622: } else { darcy@622: throw new Exception(); darcy@622: } darcy@622: } darcy@622: }