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