Fri, 13 Dec 2013 14:13:03 +0000
8029721: javac crash for annotated parameter type of lambda in a field
Reviewed-by: rfield, jfranck
1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 /*
25 * @test
26 * @bug 8008077 8029721
27 * @summary Test population of reference info for lambda expressions
28 * javac crash for annotated parameter type of lambda in a field
29 * @compile -g Driver.java ReferenceInfoUtil.java Lambda.java
30 * @run main Driver Lambda
31 * @author Werner Dietl
32 */
34 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
36 public class Lambda {
38 @TADescriptions({
39 @TADescription(annotation = "TA", type = METHOD_REFERENCE,
40 offset = ReferenceInfoUtil.IGNORE_VALUE),
41 @TADescription(annotation = "TB", type = METHOD_REFERENCE,
42 offset = ReferenceInfoUtil.IGNORE_VALUE)
43 })
44 public String returnMethodRef1() {
45 return
46 "class Lambda {" +
47 " public String getName() { return \"Lambda!\"; }" +
48 "}" +
50 "class Test {" +
51 " java.util.function.Function<Lambda, String> lambda() {" +
52 " return @TA @TB Lambda::getName;" +
53 " }" +
54 "}";
55 }
57 @TADescriptions({
58 @TADescription(annotation = "TA", type = METHOD_REFERENCE,
59 offset = ReferenceInfoUtil.IGNORE_VALUE),
60 @TADescription(annotation = "TB", type = METHOD_REFERENCE,
61 offset = ReferenceInfoUtil.IGNORE_VALUE,
62 genericLocation = { 3, 0 }),
63 @TADescription(annotation = "TC", type = METHOD_REFERENCE,
64 offset = ReferenceInfoUtil.IGNORE_VALUE,
65 genericLocation = { 3, 0 }),
66 @TADescription(annotation = "TD", type = METHOD_REFERENCE,
67 offset = ReferenceInfoUtil.IGNORE_VALUE,
68 genericLocation = { 3, 1 }),
69 @TADescription(annotation = "TE", type = METHOD_REFERENCE,
70 offset = ReferenceInfoUtil.IGNORE_VALUE,
71 genericLocation = { 3, 1 })
72 })
73 public String returnMethodRef2() {
74 return
75 "class Lambda<S, T> {" +
76 " public String getName() { return \"Lambda!\"; }" +
77 "}" +
79 "class Test {" +
80 " java.util.function.Function<Lambda<Integer, Float>, String> lambda() {" +
81 " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::getName;" +
82 " }" +
83 "}";
84 }
86 @TADescriptions({
87 @TADescription(annotation = "CTA", type = METHOD_REFERENCE,
88 offset = ReferenceInfoUtil.IGNORE_VALUE),
89 @TADescription(annotation = "CTB", type = METHOD_REFERENCE,
90 offset = ReferenceInfoUtil.IGNORE_VALUE,
91 genericLocation = { 3, 0 }),
92 @TADescription(annotation = "CTC", type = METHOD_REFERENCE,
93 offset = ReferenceInfoUtil.IGNORE_VALUE,
94 genericLocation = { 3, 1 })
95 })
96 public String returnMethodRef3() {
97 return
98 "class Lambda<S, T> {" +
99 " public String getName() { return \"Lambda!\"; }" +
100 "}" +
102 "@Target(ElementType.TYPE_USE)" +
103 "@interface CTA {" +
104 " String value();" +
105 "}" +
107 "@Target(ElementType.TYPE_USE)" +
108 "@interface CTB {" +
109 " int age();" +
110 "}" +
112 "@Target(ElementType.TYPE_USE)" +
113 "@interface CTC {" +
114 " String name();" +
115 "}" +
117 "class Test {" +
118 " java.util.function.Function<Lambda<Integer, Float>, String> lambda() {" +
119 " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::getName;" +
120 " }" +
121 "}";
122 }
125 @TADescriptions({
126 @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE,
127 offset = ReferenceInfoUtil.IGNORE_VALUE),
128 @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE,
129 offset = ReferenceInfoUtil.IGNORE_VALUE)
130 })
131 public String returnConstructorRef1() {
132 return
133 "class Lambda {" +
134 " Lambda() { }" +
135 "}" +
137 "class Test {" +
138 " Runnable lambda() {" +
139 " return @TA @TB Lambda::new;" +
140 " }" +
141 "}";
142 }
144 @TADescriptions({
145 @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE,
146 offset = ReferenceInfoUtil.IGNORE_VALUE),
147 @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE,
148 offset = ReferenceInfoUtil.IGNORE_VALUE,
149 genericLocation = { 3, 0 }),
150 @TADescription(annotation = "TC", type = CONSTRUCTOR_REFERENCE,
151 offset = ReferenceInfoUtil.IGNORE_VALUE,
152 genericLocation = { 3, 0 }),
153 @TADescription(annotation = "TD", type = CONSTRUCTOR_REFERENCE,
154 offset = ReferenceInfoUtil.IGNORE_VALUE,
155 genericLocation = { 3, 1 }),
156 @TADescription(annotation = "TE", type = CONSTRUCTOR_REFERENCE,
157 offset = ReferenceInfoUtil.IGNORE_VALUE,
158 genericLocation = { 3, 1 })
159 })
160 public String returnConstructorRef2() {
161 return
162 "class Lambda<S, T> {" +
163 " Lambda() { }" +
164 "}" +
166 "class Test {" +
167 " Runnable lambda() {" +
168 " return @TA Lambda<@TB @TC Integer, @TD @TE Float>::new;" +
169 " }" +
170 "}";
171 }
173 @TADescriptions({
174 @TADescription(annotation = "CTA", type = CONSTRUCTOR_REFERENCE,
175 offset = ReferenceInfoUtil.IGNORE_VALUE),
176 @TADescription(annotation = "CTB", type = CONSTRUCTOR_REFERENCE,
177 offset = ReferenceInfoUtil.IGNORE_VALUE,
178 genericLocation = { 3, 0 }),
179 @TADescription(annotation = "CTC", type = CONSTRUCTOR_REFERENCE,
180 offset = ReferenceInfoUtil.IGNORE_VALUE,
181 genericLocation = { 3, 1 })
182 })
183 public String returnConstructorRef3() {
184 return
185 "class Lambda<S, T> {" +
186 " Lambda() { }" +
187 "}" +
189 "@Target(ElementType.TYPE_USE)" +
190 "@interface CTA {" +
191 " String value();" +
192 "}" +
194 "@Target(ElementType.TYPE_USE)" +
195 "@interface CTB {" +
196 " int age();" +
197 "}" +
199 "@Target(ElementType.TYPE_USE)" +
200 "@interface CTC {" +
201 " String name();" +
202 "}" +
204 "class Test {" +
205 " Runnable lambda() {" +
206 " return @CTA(\"x\") Lambda<@CTB(age = 5) Integer, @CTC(name = \"y\") Float>::new;" +
207 " }" +
208 "}";
209 }
212 @TADescriptions({
213 @TADescription(annotation = "TA", type = METHOD_REFERENCE_TYPE_ARGUMENT,
214 offset = ReferenceInfoUtil.IGNORE_VALUE,
215 typeIndex = 0),
216 @TADescription(annotation = "TB", type = METHOD_REFERENCE_TYPE_ARGUMENT,
217 offset = ReferenceInfoUtil.IGNORE_VALUE,
218 typeIndex = 1)
219 })
220 public String returnMethodRefTA1() {
221 return
222 "interface Lambda {" +
223 " <S, T> void generic(S p1, T p2);" +
224 "}" +
226 "class LambdaImpl implements Lambda {" +
227 " public <S, T> void generic(S p1, T p2) {}" +
228 "}" +
230 "class Test {" +
231 " Lambda lambda(LambdaImpl r) {" +
232 " return r::<@TA Object, @TB Object>generic;" +
233 " }" +
234 "}";
235 }
237 @TADescriptions({
238 @TADescription(annotation = "TA", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT,
239 offset = ReferenceInfoUtil.IGNORE_VALUE,
240 typeIndex = 0),
241 @TADescription(annotation = "TB", type = CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT,
242 offset = ReferenceInfoUtil.IGNORE_VALUE,
243 typeIndex = 1)
244 })
245 public String returnConstructorRefTA2() {
246 return
247 "interface Lambda {" +
248 " <S, T> void generic(S p1, T p2);" +
249 "}" +
251 "class LambdaImpl implements Lambda {" +
252 " <S, T> LambdaImpl(S p1, T p2) {}" +
253 " public <S, T> void generic(S p1, T p2) {}" +
254 "}" +
256 "class Test {" +
257 " Lambda lambda() {" +
258 " return LambdaImpl::<@TA Object, @TB Object>new;" +
259 " }" +
260 "}";
261 }
263 @TADescriptions({
264 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
265 paramIndex = 0),
266 @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
267 paramIndex = 1),
268 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
269 paramIndex = 1, genericLocation = { 3, 0 }),
270 @TADescription(annotation = "TD", type = LOCAL_VARIABLE,
271 lvarOffset = ReferenceInfoUtil.IGNORE_VALUE,
272 lvarLength = ReferenceInfoUtil.IGNORE_VALUE,
273 lvarIndex = ReferenceInfoUtil.IGNORE_VALUE),
274 @TADescription(annotation = "TE", type = CAST,
275 offset = ReferenceInfoUtil.IGNORE_VALUE,
276 typeIndex = 0)
277 })
278 public String returnLambdaExpr1() {
279 return
280 "interface LambdaInt {" +
281 " void lambda(Object p1, List<Object> p2);" +
282 "}" +
283 "class Test {" +
284 " LambdaInt getLambda() {" +
285 " return (@TA Object x, @TB List<@TC Object> y) -> { @TD Object l = null; System.out.println((@TE Object) l); };" +
286 " }" +
287 "}";
288 }
290 @TADescriptions({
291 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
292 paramIndex = 0)})
293 public String lambdaField1() {
294 return
295 "class Test {" +
296 " java.util.function.IntUnaryOperator field = (@TA int y) -> 1;" +
297 "}";
298 }
300 @TADescriptions({
301 @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
302 paramIndex = 0)})
303 public String lambdaField2() {
304 return
305 "class Test {" +
306 " static java.util.function.IntUnaryOperator field = (@TA int y) -> 1;" +
307 "}";
308 }
309 }