langtools/test/tools/javac/lambda/LambdaMultiCatchTest.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 24224 b31b4a230595
permissions -rw-r--r--
8133671: langtools tests have bad license Summary: Dropped classpath exception from copyright notice in tests. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24224
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     1
/*
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     4
 *
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 24224
diff changeset
     7
 * published by the Free Software Foundation.
24224
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     8
 *
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    13
 * accompanied this code).
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    14
 *
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    18
 *
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    21
 * questions.
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    22
 */
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    23
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    24
/**
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    25
 * @test
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    26
 * @bug 8036942
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    27
 * @summary javac generates incorrect exception table for multi-catch statements inside a lambda
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    28
 * @run main LambdaMultiCatchTest
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    29
 */
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    30
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    31
import java.io.IOException;
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    32
import java.util.function.Function;
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    33
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    34
public class LambdaMultiCatchTest {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    35
    public static void main(String[] args) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    36
        Function<String,String> fi = x -> {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    37
            String result = "nada";
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    38
            try {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    39
                switch (x) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    40
                    case "IO":  throw new IOException();
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    41
                    case "Illegal": throw new IllegalArgumentException();
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    42
                    case "Run": throw new RuntimeException();
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    43
                }
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    44
            } catch (IOException|IllegalArgumentException ex) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    45
               result = "IO/Illegal";
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    46
            } catch (Exception ex) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    47
               result = "Any";
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    48
            };
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    49
            return result;
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    50
        };
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    51
        String val = fi.apply("Run");
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    52
        if (!val.equals("Any")) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    53
            throw new AssertionError("Fail: Expected 'Any' but got '" + val + "'");
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    54
        }
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    55
    }
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    56
}