langtools/test/tools/javac/lambda/LambdaMultiCatchTest.java
author rfield
Wed, 30 Apr 2014 18:19:23 -0700
changeset 24224 b31b4a230595
child 32337 c9d3ab9f601c
permissions -rw-r--r--
8036942: javac generates incorrect exception table for multi-catch statements inside a lambda Summary: Union type info lost and also union type is not processed by TreeMaker.Type -- address by using existing tree, thus by-passing such issues. Reviewed-by: vromero, jlahoda
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
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    10
 *
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    11
 * 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
    12
 * 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
    13
 * 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
    14
 * 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
    15
 * accompanied this code).
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    16
 *
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    17
 * 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
    18
 * 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
    19
 * 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
    20
 *
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    21
 * 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
    22
 * 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
    23
 * questions.
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
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    26
/**
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    27
 * @test
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    28
 * @bug 8036942
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    29
 * @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
    30
 * @run main LambdaMultiCatchTest
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    31
 */
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    32
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    33
import java.io.IOException;
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    34
import java.util.function.Function;
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    35
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    36
public class LambdaMultiCatchTest {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    37
    public static void main(String[] args) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    38
        Function<String,String> fi = x -> {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    39
            String result = "nada";
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    40
            try {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    41
                switch (x) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    42
                    case "IO":  throw new IOException();
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    43
                    case "Illegal": throw new IllegalArgumentException();
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    44
                    case "Run": throw new RuntimeException();
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    45
                }
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    46
            } catch (IOException|IllegalArgumentException ex) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    47
               result = "IO/Illegal";
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    48
            } catch (Exception ex) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    49
               result = "Any";
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
            return result;
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    52
        };
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    53
        String val = fi.apply("Run");
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    54
        if (!val.equals("Any")) {
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    55
            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
    56
        }
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    57
    }
b31b4a230595 8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
diff changeset
    58
}