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