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