1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/api/6421111/T6421111.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,106 @@ 1.4 +/* 1.5 + * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6421111 1.30 + * @summary NullPointerException thrown when retrieving bounds for the type parameter 1.31 + * @author Peter von der Ah\u00e9 1.32 + * @library ../lib 1.33 + * @compile -Xlint:all T6421111.java 1.34 + * @run main T6421111 1.35 + */ 1.36 + 1.37 +import java.io.File; 1.38 +import java.net.URI; 1.39 +import java.util.Arrays; 1.40 +import java.util.Collections; 1.41 +import java.util.Set; 1.42 +import javax.annotation.processing.AbstractProcessor; 1.43 +import javax.annotation.processing.RoundEnvironment; 1.44 +import javax.annotation.processing.SupportedAnnotationTypes; 1.45 +import javax.annotation.processing.SupportedSourceVersion; 1.46 +import javax.lang.model.SourceVersion; 1.47 +import javax.lang.model.element.TypeElement; 1.48 +import javax.lang.model.element.TypeParameterElement; 1.49 +import javax.lang.model.type.DeclaredType; 1.50 +import javax.lang.model.type.TypeVariable; 1.51 +import javax.tools.SimpleJavaFileObject; 1.52 + 1.53 +import static javax.tools.JavaFileObject.Kind.SOURCE; 1.54 + 1.55 +public class T6421111 extends ToolTester { 1.56 + void test(String... args) { 1.57 + class Test1 extends SimpleJavaFileObject { 1.58 + Test1() { 1.59 + super(URI.create("myfo:///Test1.java"), SOURCE); 1.60 + } 1.61 + @Override 1.62 + public String getCharContent(boolean ignoreEncodingErrors) { 1.63 + return "class Test1<T extends Thread & Runnable> {}"; 1.64 + } 1.65 + } 1.66 + class Test2 extends SimpleJavaFileObject { 1.67 + Test2() { 1.68 + super(URI.create("myfo:///Test2.java"), SOURCE); 1.69 + } 1.70 + @Override 1.71 + public String getCharContent(boolean ignoreEncodingErrors) { 1.72 + return "class Test2<T extends Test2<T> & Runnable> {}"; 1.73 + } 1.74 + } 1.75 + task = tool.getTask(null, fm, null, Collections.singleton("-Xlint:all"), null, 1.76 + Arrays.asList(new Test1(), new Test2())); 1.77 + task.setProcessors(Collections.singleton(new MyProcessor())); 1.78 + if (!task.call()) 1.79 + throw new AssertionError("Annotation processor failed"); 1.80 + } 1.81 + @SupportedAnnotationTypes("*") 1.82 + @SupportedSourceVersion(SourceVersion.RELEASE_6) 1.83 + static class MyProcessor extends AbstractProcessor { 1.84 + void test(TypeElement element, boolean fbound) { 1.85 + TypeParameterElement tpe = element.getTypeParameters().iterator().next(); 1.86 + tpe.getBounds().getClass(); 1.87 + if (fbound) { 1.88 + DeclaredType type = (DeclaredType)tpe.getBounds().get(0); 1.89 + if (type.asElement() != element) 1.90 + throw error("%s != %s", type.asElement(), element); 1.91 + TypeVariable tv = (TypeVariable)type.getTypeArguments().get(0); 1.92 + if (tv.asElement() != tpe) 1.93 + throw error("%s != %s", tv.asElement(), tpe); 1.94 + } 1.95 + } 1.96 + public boolean process(Set<? extends TypeElement> annotations, 1.97 + RoundEnvironment roundEnv) { 1.98 + test(processingEnv.getElementUtils().getTypeElement("Test1"), false); 1.99 + test(processingEnv.getElementUtils().getTypeElement("Test2"), true); 1.100 + return false; 1.101 + } 1.102 + } 1.103 + public static void main(String... args) { 1.104 + new T6421111().test(args); 1.105 + } 1.106 + public static AssertionError error(String format, Object... args) { 1.107 + return new AssertionError(String.format(format, args)); 1.108 + } 1.109 +}