duke@1: /* duke@1: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: /* duke@1: * @test duke@1: * @bug 6421111 duke@1: * @summary NullPointerException thrown when retrieving bounds for the type parameter duke@1: * @author Peter von der Ah\u00e9 duke@1: * @library ../lib duke@1: * @compile -Xlint:all T6421111.java duke@1: * @run main T6421111 duke@1: */ duke@1: duke@1: import java.io.File; duke@1: import java.net.URI; duke@1: import java.util.Arrays; duke@1: import java.util.Collections; duke@1: import java.util.Set; duke@1: import javax.annotation.processing.AbstractProcessor; duke@1: import javax.annotation.processing.RoundEnvironment; duke@1: import javax.annotation.processing.SupportedAnnotationTypes; duke@1: import javax.annotation.processing.SupportedSourceVersion; duke@1: import javax.lang.model.SourceVersion; duke@1: import javax.lang.model.element.TypeElement; duke@1: import javax.lang.model.element.TypeParameterElement; duke@1: import javax.lang.model.type.DeclaredType; duke@1: import javax.lang.model.type.TypeVariable; duke@1: import javax.tools.SimpleJavaFileObject; duke@1: duke@1: import static javax.tools.JavaFileObject.Kind.SOURCE; duke@1: duke@1: public class T6421111 extends ToolTester { duke@1: void test(String... args) { duke@1: class Test1 extends SimpleJavaFileObject { duke@1: Test1() { duke@1: super(URI.create("myfo:///Test1.java"), SOURCE); duke@1: } duke@1: @Override duke@1: public String getCharContent(boolean ignoreEncodingErrors) { duke@1: return "class Test1 {}"; duke@1: } duke@1: } duke@1: class Test2 extends SimpleJavaFileObject { duke@1: Test2() { duke@1: super(URI.create("myfo:///Test2.java"), SOURCE); duke@1: } duke@1: @Override duke@1: public String getCharContent(boolean ignoreEncodingErrors) { duke@1: return "class Test2 & Runnable> {}"; duke@1: } duke@1: } duke@1: task = tool.getTask(null, fm, null, Collections.singleton("-Xlint:all"), null, duke@1: Arrays.asList(new Test1(), new Test2())); duke@1: task.setProcessors(Collections.singleton(new MyProcessor())); duke@1: if (!task.call()) duke@1: throw new AssertionError("Annotation processor failed"); duke@1: } duke@1: @SupportedAnnotationTypes("*") duke@1: static class MyProcessor extends AbstractProcessor { duke@1: void test(TypeElement element, boolean fbound) { duke@1: TypeParameterElement tpe = element.getTypeParameters().iterator().next(); duke@1: tpe.getBounds().getClass(); duke@1: if (fbound) { duke@1: DeclaredType type = (DeclaredType)tpe.getBounds().get(0); duke@1: if (type.asElement() != element) duke@1: throw error("%s != %s", type.asElement(), element); duke@1: TypeVariable tv = (TypeVariable)type.getTypeArguments().get(0); duke@1: if (tv.asElement() != tpe) duke@1: throw error("%s != %s", tv.asElement(), tpe); duke@1: } duke@1: } duke@1: public boolean process(Set annotations, duke@1: RoundEnvironment roundEnv) { duke@1: test(processingEnv.getElementUtils().getTypeElement("Test1"), false); duke@1: test(processingEnv.getElementUtils().getTypeElement("Test2"), true); duke@1: return false; duke@1: } darcy@495: @Override darcy@495: public SourceVersion getSupportedSourceVersion() { darcy@495: return SourceVersion.latest(); darcy@495: } duke@1: } duke@1: public static void main(String... args) { duke@1: new T6421111().test(args); duke@1: } duke@1: public static AssertionError error(String format, Object... args) { duke@1: return new AssertionError(String.format(format, args)); duke@1: } duke@1: }