8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata

Reviewed-by: vromero
This commit is contained in:
Srikanth Adayapalam 2017-01-23 10:28:52 +05:30
parent ce3452952c
commit 4141792982
5 changed files with 64 additions and 8 deletions
langtools
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/tools/javac

@ -2820,7 +2820,7 @@ public class Check {
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) {

@ -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;
}
}

@ -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) {}
}

@ -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

@ -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 @@ public class AnnotationsOnModules extends ModuleTestBase {
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 @@ public class AnnotationsOnModules extends ModuleTestBase {
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 @@ public class AnnotationsOnModules extends ModuleTestBase {
.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);
}