test/tools/javac/generics/7015430/T7015430.java

Thu, 25 Aug 2011 17:18:25 -0700

author
schien
date
Thu, 25 Aug 2011 17:18:25 -0700
changeset 1067
f497fac86cf9
parent 895
9286a5d1fae3
child 1896
44e27378f523
permissions
-rw-r--r--

Added tag jdk8-b02 for changeset b3c059de2a61

     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  */
    11 class T7015430 {
    12     static <E extends Exception> Iterable<E> empty(Iterable<E> arg) throws E {
    13         return null;
    14     }
    16     <E extends Exception> T7015430(Iterable<E> arg) throws E { }
    18     static <E extends Exception> Iterable<E> empty2(Iterable x) throws E {
    19         return null;
    20     }
    22     static class Foo<X extends Exception> {
    23         Foo() throws X {}
    24     }
    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     }
    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     }
    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     }
    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     }
    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     }
    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     }
    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     }
    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     }
    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     }
   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     }
   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     }
   124     /**
   125     * Constructor invocation, no unchecked, inferred arguments (diamond)
   126     * inferred: Exception - should fail
   127     */
   128     void m12() {
   129         new Foo<>();
   130     }
   131 }

mercurial