langtools/test/tools/javac/T8022316/CompilerErrorGenericThrowPlusMethodRefTest.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 19655 39cf56516b13
child 32338 8b2183276f84
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:
19655
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
     1
/*
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
     4
 *
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
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: 19655
diff changeset
     7
 * published by the Free Software Foundation.
19655
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
     8
 *
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    13
 * accompanied this code).
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    14
 *
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    18
 *
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    21
 * questions.
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    22
 */
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    23
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    24
/*
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    25
 * @test
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    26
 * @bug 8022316
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    27
 * @summary Generic throws, overriding and method reference
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    28
 * @compile/fail/ref=CompilerErrorGenericThrowPlusMethodRefTest.out -XDrawDiagnostics CompilerErrorGenericThrowPlusMethodRefTest.java
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    29
 */
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    30
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    31
@SuppressWarnings("unchecked")
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    32
public class CompilerErrorGenericThrowPlusMethodRefTest {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    33
    interface SAM11 {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    34
        public <E extends Throwable> void foo() throws E ;
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    35
    }
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    36
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    37
    interface SAM12 extends SAM11{
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    38
        @Override
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    39
        public void foo() throws Throwable;
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    40
    }
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    41
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    42
    public void boo() throws RuntimeException {}
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    43
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    44
    static void test1() {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    45
        try {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    46
            SAM12 s2 = new CompilerErrorGenericThrowPlusMethodRefTest()::boo;
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    47
            s2.foo();
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    48
        } catch(Throwable ex) {}
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    49
    }
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    50
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    51
    static void test2() {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    52
        SAM11 s1 = null;
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    53
        s1.<Exception>foo();
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    54
        s1.<RuntimeException>foo();
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    55
    }
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    56
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    57
    interface SAM21 {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    58
        <E extends Exception> void m(E arg) throws E;
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    59
    }
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    60
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    61
    interface SAM22 {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    62
        <F extends Exception> void m(F arg) throws F;
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    63
    }
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    64
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    65
    interface SAM23 extends SAM21, SAM22 {}
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    66
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    67
    public <E extends Exception> void bar(E e) throws E {}
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    68
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    69
    static <E extends Exception> void test3(E e) {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    70
        try {
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    71
            SAM23 s2 = new CompilerErrorGenericThrowPlusMethodRefTest()::bar;
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    72
            s2.m(e);
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    73
        } catch(Exception ex) {}
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    74
    }
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    75
39cf56516b13 8022316: Generic throws, overriding and method reference
vromero
parents:
diff changeset
    76
}