608N/A/*
839N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
608N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
608N/A *
608N/A * This code is free software; you can redistribute it and/or modify it
608N/A * under the terms of the GNU General Public License version 2 only, as
608N/A * published by the Free Software Foundation.
608N/A *
608N/A * This code is distributed in the hope that it will be useful, but WITHOUT
608N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
608N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
608N/A * version 2 for more details (a copy is included in the LICENSE file that
608N/A * accompanied this code).
608N/A *
608N/A * You should have received a copy of the GNU General Public License version
608N/A * 2 along with this work; if not, write to the Free Software Foundation,
608N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
608N/A *
608N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
608N/A * or visit www.oracle.com if you need additional information or have any
608N/A * questions.
608N/A */
608N/A
608N/A/*
608N/A * @test
839N/A * @bug 6911256 6964740 7013420
608N/A * @author Joseph D. Darcy
608N/A * @summary Test that TWR and multi-catch play well together
608N/A * @compile TwrMultiCatch.java
608N/A * @run main TwrMultiCatch
608N/A */
608N/A
608N/Aimport java.io.IOException;
608N/Apublic class TwrMultiCatch implements AutoCloseable {
608N/A private final Class<? extends Exception> exceptionClass;
608N/A
608N/A private TwrMultiCatch(Class<? extends Exception> exceptionClass) {
608N/A this.exceptionClass = exceptionClass;
608N/A }
608N/A
608N/A public static void main(String... args) {
608N/A test(new TwrMultiCatch(CustomCloseException1.class),
608N/A CustomCloseException1.class);
608N/A
608N/A test(new TwrMultiCatch(CustomCloseException2.class),
608N/A CustomCloseException2.class);
608N/A }
608N/A
608N/A private static void test(TwrMultiCatch twrMultiCatch,
608N/A Class<? extends Exception> expected) {
839N/A try(TwrMultiCatch tmc = twrMultiCatch) {
839N/A System.out.println(tmc.toString());
839N/A } catch (CustomCloseException1 |
608N/A CustomCloseException2 exception) {
608N/A if (!exception.getClass().equals(expected) ) {
608N/A throw new RuntimeException("Unexpected catch!");
608N/A }
608N/A }
608N/A }
608N/A
608N/A public void close() throws CustomCloseException1, CustomCloseException2 {
608N/A Throwable t;
608N/A try {
608N/A t = exceptionClass.newInstance();
608N/A } catch(ReflectiveOperationException rfe) {
608N/A throw new RuntimeException(rfe);
608N/A }
608N/A
608N/A try {
608N/A throw t;
839N/A } catch (CustomCloseException1 |
608N/A CustomCloseException2 exception) {
608N/A throw exception;
608N/A } catch (Throwable throwable) {
608N/A throw new RuntimeException(throwable);
608N/A }
608N/A }
608N/A}
608N/A
608N/Aclass CustomCloseException1 extends Exception {}
608N/Aclass CustomCloseException2 extends Exception {}