Fri, 29 Apr 2011 16:06:28 +0100
6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
Summary: Accessing a non-existing enum constant from an annotation whose class is available results in an internal error
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. |
duke@1 | 8 | * |
duke@1 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 13 | * accompanied this code). |
duke@1 | 14 | * |
duke@1 | 15 | * You should have received a copy of the GNU General Public License version |
duke@1 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
duke@1 | 22 | */ |
duke@1 | 23 | |
duke@1 | 24 | /* |
duke@1 | 25 | * @test |
duke@1 | 26 | * @bug 6468404 |
duke@1 | 27 | * @summary ExecutableElement.getParameters() uses raw type for class loaded from -g bytecode |
duke@1 | 28 | * @author jesse.glick@... |
duke@1 | 29 | * @author Peter von der Ah\u00e9 |
duke@1 | 30 | * @library ../lib |
duke@1 | 31 | * @compile T6468404.java |
duke@1 | 32 | * @run main T6468404 |
duke@1 | 33 | */ |
duke@1 | 34 | |
duke@1 | 35 | import java.io.IOException; |
duke@1 | 36 | import java.net.URI; |
duke@1 | 37 | import java.util.Arrays; |
duke@1 | 38 | import java.util.Collections; |
duke@1 | 39 | import java.util.Set; |
duke@1 | 40 | import javax.annotation.processing.AbstractProcessor; |
duke@1 | 41 | import javax.annotation.processing.RoundEnvironment; |
duke@1 | 42 | import javax.annotation.processing.SupportedAnnotationTypes; |
duke@1 | 43 | import javax.annotation.processing.SupportedSourceVersion; |
duke@1 | 44 | import javax.annotation.processing.ProcessingEnvironment; |
duke@1 | 45 | import javax.lang.model.SourceVersion; |
duke@1 | 46 | import javax.lang.model.element.ExecutableElement; |
duke@1 | 47 | import javax.lang.model.element.TypeElement; |
duke@1 | 48 | import javax.lang.model.type.ExecutableType; |
duke@1 | 49 | import javax.lang.model.type.DeclaredType; |
duke@1 | 50 | import javax.lang.model.type.TypeMirror; |
duke@1 | 51 | import javax.lang.model.util.Elements; |
duke@1 | 52 | import javax.tools.JavaCompiler; |
duke@1 | 53 | import javax.tools.JavaFileObject; |
duke@1 | 54 | import javax.tools.SimpleJavaFileObject; |
duke@1 | 55 | import javax.tools.ToolProvider; |
duke@1 | 56 | |
duke@1 | 57 | public class T6468404 extends ToolTester { |
duke@1 | 58 | void test(String... args) { |
duke@1 | 59 | System.err.println("Compiling with sources:"); |
duke@1 | 60 | task = tool.getTask( |
duke@1 | 61 | null, fm, null, null, |
duke@1 | 62 | null, Collections.singleton(new DummyFO("C"))); |
duke@1 | 63 | task.setProcessors(Collections.singleton(new P())); |
duke@1 | 64 | if (!task.call()) |
duke@1 | 65 | throw new AssertionError(); |
duke@1 | 66 | |
duke@1 | 67 | System.err.println("Compiling with binaries w/o -g:"); |
duke@1 | 68 | task = tool.getTask( |
duke@1 | 69 | null, fm, null, null, |
duke@1 | 70 | null, Collections.singleton(new DummyFO("Dummy"))); |
duke@1 | 71 | task.setProcessors(Collections.singleton(new P())); |
duke@1 | 72 | if (!task.call()) |
duke@1 | 73 | throw new AssertionError(); |
duke@1 | 74 | |
duke@1 | 75 | task = tool.getTask( |
duke@1 | 76 | null, fm, null, |
duke@1 | 77 | Arrays.asList("-g"), |
duke@1 | 78 | null, Collections.singleton(new DummyFO("C"))); |
duke@1 | 79 | if (!task.call()) |
duke@1 | 80 | throw new AssertionError(); |
duke@1 | 81 | |
duke@1 | 82 | System.err.println("Compiling with binaries w/ -g:"); |
duke@1 | 83 | task = tool.getTask( |
duke@1 | 84 | null, fm, null, null, |
duke@1 | 85 | null, Collections.singleton(new DummyFO("Dummy"))); |
duke@1 | 86 | task.setProcessors(Collections.singleton(new P())); |
duke@1 | 87 | if (!task.call()) |
duke@1 | 88 | throw new AssertionError(); |
duke@1 | 89 | } |
duke@1 | 90 | public static void main(String... args) { |
duke@1 | 91 | new T6468404().test(args); |
duke@1 | 92 | } |
duke@1 | 93 | |
duke@1 | 94 | } |
duke@1 | 95 | |
duke@1 | 96 | class DummyFO extends SimpleJavaFileObject { |
duke@1 | 97 | String n; |
duke@1 | 98 | public DummyFO(String n) { |
duke@1 | 99 | super(URI.create("nowhere:/" + n + ".java"), JavaFileObject.Kind.SOURCE); |
duke@1 | 100 | this.n = n; |
duke@1 | 101 | } |
duke@1 | 102 | public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
duke@1 | 103 | return "public class " + n + " {" + n + "(java.util.List<String> l) {}}"; |
duke@1 | 104 | } |
duke@1 | 105 | } |
duke@1 | 106 | |
duke@1 | 107 | @SupportedAnnotationTypes("*") |
duke@1 | 108 | class P extends AbstractProcessor { |
duke@1 | 109 | boolean ran = false; |
duke@1 | 110 | |
duke@1 | 111 | Elements elements; |
duke@1 | 112 | |
duke@1 | 113 | @Override |
duke@1 | 114 | public synchronized void init(ProcessingEnvironment processingEnv) { |
duke@1 | 115 | super.init(processingEnv); |
duke@1 | 116 | elements = processingEnv.getElementUtils(); |
duke@1 | 117 | } |
duke@1 | 118 | |
duke@1 | 119 | ExecutableElement getFirstMethodIn(String name) { |
duke@1 | 120 | return (ExecutableElement)elements.getTypeElement(name).getEnclosedElements().get(0); |
duke@1 | 121 | } |
duke@1 | 122 | |
duke@1 | 123 | boolean isParameterized(TypeMirror type) { |
duke@1 | 124 | return !((DeclaredType)type).getTypeArguments().isEmpty(); |
duke@1 | 125 | } |
duke@1 | 126 | |
duke@1 | 127 | @Override |
duke@1 | 128 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
duke@1 | 129 | if (!ran) { |
duke@1 | 130 | ran = true; |
duke@1 | 131 | ExecutableElement m = getFirstMethodIn("C"); |
duke@1 | 132 | System.err.println("method: " + m); |
duke@1 | 133 | |
duke@1 | 134 | TypeMirror type = (DeclaredType)m.getParameters().get(0).asType(); |
duke@1 | 135 | System.err.println("parameters[0]: " + type); |
duke@1 | 136 | if (!isParameterized(type)) |
duke@1 | 137 | throw new AssertionError(type); |
duke@1 | 138 | |
duke@1 | 139 | type = ((ExecutableType)m.asType()).getParameterTypes().get(0); |
duke@1 | 140 | System.err.println("parameterTypes[0]: " + type); |
duke@1 | 141 | if (!isParameterized(type)) |
duke@1 | 142 | throw new AssertionError(type); |
duke@1 | 143 | System.err.println(); |
duke@1 | 144 | } |
duke@1 | 145 | return true; |
duke@1 | 146 | } |
darcy@495 | 147 | |
darcy@495 | 148 | @Override |
darcy@495 | 149 | public SourceVersion getSupportedSourceVersion() { |
darcy@495 | 150 | return SourceVersion.latest(); |
darcy@495 | 151 | } |
duke@1 | 152 | } |