Wed, 17 Jul 2013 14:04:01 +0100
8012242: Lambda compatibility and checked exceptions
Summary: Inference variables in 'throws' clause with no constraints should be inferred as RuntimeException
Reviewed-by: jjg, vromero
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_1.out -source 7 -Xlint:-options,unchecked -XDrawDiagnostics T7015430.java
8 * @compile/fail/ref=T7015430_2.out -Xlint:unchecked -XDrawDiagnostics T7015430.java
9 *
10 */
12 class T7015430 {
13 static <E extends Exception> Iterable<E> empty(Iterable<E> arg) throws E {
14 return null;
15 }
17 <E extends Exception> T7015430(Iterable<E> arg) throws E { }
19 static <E extends Exception> Iterable<E> empty2(Iterable x) throws E {
20 return null;
21 }
23 static class Foo<X extends Exception> {
24 Foo() throws X {}
25 }
27 /**
28 * Method invocation, no unchecked
29 * inferred: RuntimeException - should pass
30 */
31 void m1() {
32 Iterable<RuntimeException> i = java.util.Collections.emptyList();
33 empty(i);
34 }
36 /**
37 * Method invocation, unchecked, inferred arguments
38 * inferred: Exception - should fail
39 */
40 void m2() {
41 Iterable i = java.util.Collections.EMPTY_LIST;
42 empty(i);
43 }
45 /**
46 * Method invocation, unchecked, explicit arguments
47 * inferred: RuntimeException - should pass
48 */
49 void m3() {
50 Iterable i = java.util.Collections.EMPTY_LIST;
51 T7015430.<RuntimeException>empty(i);
52 }
54 /**
55 * Constructor invocation, no unchecked
56 * inferred: RuntimeException - should pass
57 */
58 void m4() {
59 Iterable<RuntimeException> i = java.util.Collections.emptyList();
60 new T7015430(i);
61 }
63 /**
64 * Constructor invocation, unchecked, inferred arguments
65 * inferred: Exception - should fail
66 */
67 void m5() {
68 Iterable i = java.util.Collections.EMPTY_LIST;
69 new T7015430(i);
70 }
72 /**
73 * Constructor invocation, unchecked, explicit arguments
74 * inferred: RuntimeException - should pass
75 */
76 void m6() {
77 Iterable i = java.util.Collections.EMPTY_LIST;
78 new <RuntimeException>T7015430(i);
79 }
81 /**
82 * Method invocation, no unchecked, inferred arguments
83 * inferred: RuntimeException - should pass
84 */
85 void m7() {
86 Iterable i = java.util.Collections.EMPTY_LIST;
87 Iterable<RuntimeException> e = empty2(i);
88 }
90 /**
91 * Method invocation, no unchecked, inferred arguments
92 * inferred: Exception - should fail
93 */
94 void m8() {
95 Iterable i = java.util.Collections.EMPTY_LIST;
96 empty2(i);
97 }
99 /**
100 * Constructor invocation, unchecked, explicit arguments
101 * inferred: RuntimeException - should pass
102 */
103 void m9() {
104 Iterable i = java.util.Collections.EMPTY_LIST;
105 new <RuntimeException> T7015430(i);
106 }
108 /**
109 * Constructor invocation, unchecked, inferred arguments
110 * inferred: Exception - should fail
111 */
112 void m10() {
113 Iterable i = java.util.Collections.EMPTY_LIST;
114 new T7015430(i);
115 }
117 /**
118 * Constructor invocation, no unchecked, inferred arguments (diamond)
119 * inferred: RuntimeException - should pass
120 */
121 void m11() {
122 Foo<RuntimeException> o = new Foo<>();
123 }
125 /**
126 * Constructor invocation, no unchecked, inferred arguments (diamond)
127 * inferred: Exception - should fail
128 */
129 void m12() {
130 new Foo<>();
131 }
132 }