test/tools/javac/T8024437/ExceptionInferenceFromClassFileTest.java

Wed, 14 Nov 2018 10:18:25 -0800

author
diazhou
date
Wed, 14 Nov 2018 10:18:25 -0800
changeset 3762
7909abb85562
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u201-b04 for changeset a7f48b9dfb82

     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 /*
    27  * @test
    28  * @bug 8024437
    29  * @summary Inferring the exception thrown by a lambda: sometimes fails to compile
    30  * @library /tools/javac/lib
    31  * @build ToolBox
    32  * @run main ExceptionInferenceFromClassFileTest
    33  */
    35 import java.nio.file.Files;
    36 import java.nio.file.Paths;
    38 public class ExceptionInferenceFromClassFileTest {
    40     static final String ABSrc =
    41             "class B {\n" +
    42             "    public static <E extends Throwable> void t(A<E> a) throws E {\n" +
    43             "        a.run();\n" +
    44             "    }\n" +
    45             "}\n" +
    47             "interface A<E extends Throwable> {\n" +
    48             "    void run() throws E;\n" +
    49             "}";
    51     static final String CSrc =
    52             "class C {\n" +
    53             "    public void d() {\n" +
    54             "        B.t(null);\n" +
    55             "    }\n" +
    56             "}";
    58     public static void main(String[] args) throws Exception {
    59         Files.createDirectory(Paths.get("out"));
    61         ToolBox.JavaToolArgs compileABParams =
    62                 new ToolBox.JavaToolArgs()
    63                 .setOptions("-d", "out")
    64                 .setSources(ABSrc);
    65         ToolBox.javac(compileABParams);
    67         ToolBox.JavaToolArgs compileCParams =
    68                 new ToolBox.JavaToolArgs()
    69                 .setOptions("-d", "out", "-cp", "out")
    70                 .setSources(CSrc);
    71         ToolBox.javac(compileCParams);
    72     }
    74 }

mercurial