changeset 3911:8cbff90a50bc

8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata. Reviewed-by: vromero
author sadayapalam
date Mon, 23 Jan 2017 10:28:52 +0530
parents 50c877258ca9
children 6a9dd3d893b0
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java test/tools/javac/annotations/neg/8171322/SimpleProcessor.java test/tools/javac/annotations/neg/8171322/TypeVariableAsAnnotationTest.java test/tools/javac/annotations/neg/8171322/TypeVariableAsAnnotationTest.out test/tools/javac/modules/AnnotationsOnModules.java
diffstat 5 files changed, 64 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Fri Jan 20 18:24:50 2017 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Mon Jan 23 10:28:52 2017 +0530
@@ -2820,7 +2820,7 @@
     private void validateAnnotation(JCAnnotation a, Symbol s) {
         validateAnnotationTree(a);
 
-        if (!annotationApplicable(a, s))
+        if (a.type.tsym.isAnnotationType() && !annotationApplicable(a, s))
             log.error(a.pos(), "annotation.type.not.applicable");
 
         if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/neg/8171322/SimpleProcessor.java	Mon Jan 23 10:28:52 2017 +0530
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+
+@SupportedAnnotationTypes("*")
+public class SimpleProcessor extends AbstractProcessor {
+
+  @Override
+  public SourceVersion getSupportedSourceVersion() {
+    return SourceVersion.latestSupported();
+  }
+
+  @Override
+  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+    return false;
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/neg/8171322/TypeVariableAsAnnotationTest.java	Mon Jan 23 10:28:52 2017 +0530
@@ -0,0 +1,11 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8171322
+ * @summary AssertionError in TypeSymbol.getAnnotationTypeMetadata
+ * @compile SimpleProcessor.java
+ * @compile/fail/ref=TypeVariableAsAnnotationTest.out -processor SimpleProcessor -XDrawDiagnostics TypeVariableAsAnnotationTest.java
+ */
+
+class TypeVariableAsAnnotationTest<Override> {
+  TypeVariableAsAnnotationTest(@Override String foo, @XXX String goo) {}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/neg/8171322/TypeVariableAsAnnotationTest.out	Mon Jan 23 10:28:52 2017 +0530
@@ -0,0 +1,3 @@
+TypeVariableAsAnnotationTest.java:10:33: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Override, java.lang.annotation.Annotation)
+TypeVariableAsAnnotationTest.java:10:55: compiler.err.cant.resolve.location: kindname.class, XXX, , , (compiler.misc.location: kindname.class, TypeVariableAsAnnotationTest<Override>, null)
+2 errors
\ No newline at end of file
--- a/test/tools/javac/modules/AnnotationsOnModules.java	Fri Jan 20 18:24:50 2017 -0800
+++ b/test/tools/javac/modules/AnnotationsOnModules.java	Mon Jan 23 10:28:52 2017 +0530
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8159602 8170549 8171255
+ * @bug 8159602 8170549 8171255 8171322
  * @summary Test annotations on module declaration.
  * @library /tools/lib
  * @modules jdk.compiler/com.sun.tools.javac.api
@@ -373,8 +373,8 @@
 
         tb.writeJavaFiles(m1,
                 "module A { exports p1; exports p2; }",
-                "package p1; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A { }",
-                "package p2; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A { }");
+                "package p1; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface AAA { }",
+                "package p2; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface AAA { }");
 
         Path modulePath = base.resolve("module-path");
 
@@ -390,7 +390,7 @@
         Path m2 = base.resolve("src2/B");
 
         tb.writeJavaFiles(m2,
-                "import p1.*; import p2.*; @A module B { requires A; }");
+                "import p1.*; import p2.*; @AAA module B { requires A; }");
         List<String> log = new JavacTask(tb)
                 .options("--module-source-path", m2.getParent().toString(),
                         "--module-path", modulePath.toString(),
@@ -402,9 +402,8 @@
                 .writeAll()
                 .getOutputLines(OutputKind.DIRECT);
 
-        List<String> expected = List.of("module-info.java:1:28: compiler.err.ref.ambiguous: A, kindname.class, p2.A, p2, kindname.class, p1.A, p1",
-                "module-info.java:1:27: compiler.err.annotation.type.not.applicable",
-                "2 errors");
+        List<String> expected = List.of("module-info.java:1:28: compiler.err.ref.ambiguous: AAA, kindname.class, p2.AAA, p2, kindname.class, p1.AAA, p1",
+                "1 error");
         if (!log.containsAll(expected)) {
             throw new AssertionError("Expected output not found. Expected: " + expected);
         }