langtools/test/tools/javac/generics/7015430/T7015430.java
author mcimadamore
Wed, 17 Jul 2013 14:04:01 +0100
changeset 18909 8f9fc5d876e4
parent 8616 5a47f5535883
permissions -rw-r--r--
8012242: Lambda compatibility and checked exceptions Summary: Inference variables in 'throws' clause with no constraints should be inferred as RuntimeException Reviewed-by: jjg, vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
     1
/*
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
     2
 * @test /nodynamiccopyright/
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
     3
 * @bug 7015430
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
     4
 *
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
     5
 * @summary  Incorrect thrown type determined for unchecked invocations
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
     6
 * @author Daniel Smith
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 8616
diff changeset
     7
 * @compile/fail/ref=T7015430_1.out -source 7 -Xlint:-options,unchecked -XDrawDiagnostics T7015430.java
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 8616
diff changeset
     8
 * @compile/fail/ref=T7015430_2.out -Xlint:unchecked -XDrawDiagnostics T7015430.java
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
     9
 *
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    10
 */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    11
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    12
class T7015430 {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    13
    static <E extends Exception> Iterable<E> empty(Iterable<E> arg) throws E {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    14
        return null;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    15
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    16
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    17
    <E extends Exception> T7015430(Iterable<E> arg) throws E { }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    18
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    19
    static <E extends Exception> Iterable<E> empty2(Iterable x) throws E {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    20
        return null;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    21
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    22
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    23
    static class Foo<X extends Exception> {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    24
        Foo() throws X {}
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    25
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    26
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    27
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    28
    * Method invocation, no unchecked
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    29
    * inferred: RuntimeException - should pass
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    30
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    31
    void m1() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    32
        Iterable<RuntimeException> i = java.util.Collections.emptyList();
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    33
        empty(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    34
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    35
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    36
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    37
    * Method invocation, unchecked, inferred arguments
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    38
    * inferred: Exception - should fail
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    39
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    40
    void m2() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    41
        Iterable i = java.util.Collections.EMPTY_LIST;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    42
        empty(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    43
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    44
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    45
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    46
    * Method invocation, unchecked, explicit arguments
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    47
    * inferred: RuntimeException - should pass
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    48
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    49
    void m3() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    50
        Iterable i = java.util.Collections.EMPTY_LIST;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    51
        T7015430.<RuntimeException>empty(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    52
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    53
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    54
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    55
    * Constructor invocation, no unchecked
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    56
    * inferred: RuntimeException - should pass
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    57
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    58
    void m4() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    59
        Iterable<RuntimeException> i = java.util.Collections.emptyList();
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    60
        new T7015430(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    61
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    62
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    63
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    64
    * Constructor invocation, unchecked, inferred arguments
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    65
    * inferred: Exception - should fail
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    66
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    67
    void m5() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    68
        Iterable i = java.util.Collections.EMPTY_LIST;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    69
        new T7015430(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    70
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    71
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    72
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    73
    * Constructor invocation, unchecked, explicit arguments
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    74
    * inferred: RuntimeException - should pass
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    75
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    76
    void m6() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    77
        Iterable i = java.util.Collections.EMPTY_LIST;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    78
        new <RuntimeException>T7015430(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    79
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    80
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    81
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    82
    * Method invocation, no unchecked, inferred arguments
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    83
    * inferred: RuntimeException - should pass
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    84
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    85
    void m7() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    86
        Iterable i = java.util.Collections.EMPTY_LIST;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    87
        Iterable<RuntimeException> e = empty2(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    88
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    89
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    90
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    91
    * Method invocation, no unchecked, inferred arguments
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    92
    * inferred: Exception - should fail
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    93
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    94
    void m8() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    95
        Iterable i = java.util.Collections.EMPTY_LIST;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    96
        empty2(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    97
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    98
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
    99
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   100
    * Constructor invocation, unchecked, explicit arguments
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   101
    * inferred: RuntimeException - should pass
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   102
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   103
    void m9() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   104
        Iterable i = java.util.Collections.EMPTY_LIST;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   105
        new <RuntimeException> T7015430(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   106
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   107
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   108
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   109
    * Constructor invocation, unchecked, inferred arguments
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   110
    * inferred: Exception - should fail
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   111
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   112
    void m10() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   113
        Iterable i = java.util.Collections.EMPTY_LIST;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   114
        new T7015430(i);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   115
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   116
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   117
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   118
    * Constructor invocation, no unchecked, inferred arguments (diamond)
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   119
    * inferred: RuntimeException - should pass
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   120
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   121
    void m11() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   122
        Foo<RuntimeException>  o = new Foo<>();
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   123
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   124
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   125
    /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   126
    * Constructor invocation, no unchecked, inferred arguments (diamond)
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   127
    * inferred: Exception - should fail
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   128
    */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   129
    void m12() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   130
        new Foo<>();
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   131
    }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
diff changeset
   132
}