549N/A/*
553N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
549N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
549N/A *
549N/A * This code is free software; you can redistribute it and/or modify it
549N/A * under the terms of the GNU General Public License version 2 only, as
549N/A * published by the Free Software Foundation.
549N/A *
549N/A * This code is distributed in the hope that it will be useful, but WITHOUT
549N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
549N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
549N/A * version 2 for more details (a copy is included in the LICENSE file that
549N/A * accompanied this code).
549N/A *
549N/A * You should have received a copy of the GNU General Public License version
549N/A * 2 along with this work; if not, write to the Free Software Foundation,
549N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
549N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
549N/A */
549N/A
549N/A/*
549N/A * @test
549N/A * @bug 6943289
549N/A * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
549N/A */
549N/A
549N/Aimport java.lang.annotation.*;
549N/A
549N/Apublic class Pos04 {
549N/A
549N/A enum ExceptionKind {
549N/A A(1),
549N/A B(2),
549N/A C(1);
549N/A
549N/A int expectedValue;
549N/A
549N/A ExceptionKind(int expectedValue) {
549N/A this.expectedValue = expectedValue;
549N/A }
549N/A }
549N/A
549N/A @Retention(RetentionPolicy.RUNTIME)
549N/A @interface CatchNumber {
549N/A int value();
549N/A }
549N/A
549N/A @CatchNumber(1)
549N/A static class A extends Exception { }
549N/A
549N/A @CatchNumber(2)
549N/A static class B extends Exception { }
549N/A
549N/A @CatchNumber(1)
549N/A static class C extends Exception { }
549N/A
549N/A static int sum = 0;
549N/A
549N/A public static void main(String[] args) {
549N/A for (ExceptionKind ekind : ExceptionKind.values()) {
549N/A test(ekind);
549N/A }
549N/A if (sum != 4) {
549N/A throw new Error("bad checksum - expected:4, found:" + sum);
549N/A }
549N/A }
549N/A
549N/A public static void test(ExceptionKind ekind) {
549N/A try {
549N/A switch(ekind) {
549N/A case A: throw new A();
549N/A case B: throw new B();
549N/A case C: throw new C();
549N/A }
549N/A } catch(final A | C ex) {// Catch number 1
549N/A CatchNumber catchNumber = ex.getClass().getAnnotation(CatchNumber.class);
549N/A if (catchNumber == null || catchNumber.value() != ekind.expectedValue) {
549N/A throw new Error("was expecting 1 - got " + catchNumber);
549N/A }
549N/A sum += catchNumber.value();
549N/A } catch (final B ex) { // Catch number 2
549N/A CatchNumber catchNumber = ex.getClass().getAnnotation(CatchNumber.class);
549N/A if (catchNumber == null || catchNumber.value() != ekind.expectedValue) {
549N/A throw new Error("was expecting 2 - got " + catchNumber);
549N/A }
549N/A sum += catchNumber.value();
549N/A }
549N/A }
549N/A}