Thu, 25 Jul 2013 14:51:40 +0100
8020843: javac crashes on accessibility check with method reference with typevar receiver
Summary: method reference overload check doesn't walk through type-variable receivers
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2010, 2012, 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 7159016
27 * @summary Static import of member in processor-generated class fails in JDK 7
28 * @library lib
29 * @build JavacTestingAbstractProcessor
30 * @run main T7159016
31 * @author Jessie Glick
32 */
34 import java.io.File;
35 import java.io.FileWriter;
36 import java.io.IOException;
37 import java.io.Writer;
38 import java.util.Collections;
39 import java.util.Set;
40 import javax.annotation.processing.AbstractProcessor;
41 import javax.annotation.processing.RoundEnvironment;
42 import javax.annotation.processing.SupportedAnnotationTypes;
43 import javax.annotation.processing.SupportedSourceVersion;
44 import javax.lang.model.SourceVersion;
45 import javax.lang.model.element.TypeElement;
46 import javax.tools.Diagnostic;
47 import javax.tools.JavaCompiler;
48 import javax.tools.ToolProvider;
50 public class T7159016 {
51 public static void main(String[] args) throws Exception {
52 File src = new File("C.java");
53 Writer w = new FileWriter(src);
54 try {
55 w.write("import static p.Generated.m;\nclass C { {m(); } }\n");
56 w.flush();
57 } finally {
58 w.close();
59 }
60 JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
61 JavaCompiler.CompilationTask task = jc.getTask(null, null, null, null, null,
62 jc.getStandardFileManager(null, null, null).getJavaFileObjects(src));
63 task.setProcessors(Collections.singleton(new Proc()));
64 if (!task.call()) {
65 throw new Error("Test failed");
66 }
67 }
69 private static class Proc extends JavacTestingAbstractProcessor {
70 int written;
71 @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
72 if (roundEnv.processingOver() || written++ > 0) {
73 return false;
74 }
75 messager.printMessage(Diagnostic.Kind.NOTE, "writing Generated.java");
76 try {
77 Writer w = processingEnv.getFiler().createSourceFile("p.Generated").openWriter();
78 try {
79 w.write("package p; public class Generated { public static void m() { } }");
80 } finally {
81 w.close();
82 }
83 } catch (IOException x) {
84 messager.printMessage(Diagnostic.Kind.ERROR, x.toString());
85 }
86 return true;
87 }
88 }
89 }