8043984: Confusing (incorrect) error message on repeatable annotations
authoralundblad
Fri, 17 Apr 2015 12:37:11 +0200
changeset 29960 d20c04ed8ffe
parent 29959 61bfc66866da
child 29961 a136157ff9ef
8043984: Confusing (incorrect) error message on repeatable annotations Summary: Adjusted error mesage for repeating annotations Reviewed-by: jfranck, dlsmith
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/test/tools/javac/annotations/repeatingAnnotations/RepeatingTargetNotAllowed.out
langtools/test/tools/javac/diags/examples/NonApplicableRepeatingAnno.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java	Fri Apr 17 11:52:10 2015 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java	Fri Apr 17 12:37:11 2015 +0200
@@ -31,6 +31,7 @@
 import com.sun.tools.javac.code.Scope.WriteableScope;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.TypeMetadata.Entry.Kind;
+import com.sun.tools.javac.resources.CompilerProperties.Errors;
 import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.tree.JCTree.*;
 import com.sun.tools.javac.tree.TreeInfo;
@@ -778,9 +779,10 @@
                 Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p));
                 JCAnnotation annoTree = m.Annotation(c);
 
-                if (!chk.annotationApplicable(annoTree, on))
-                    log.error(annoTree.pos(), "invalid.repeatable.annotation.incompatible.target",
-                            targetContainerType, origAnnoType);
+                if (!chk.annotationApplicable(annoTree, on)) {
+                    log.error(annoTree.pos(),
+                              Errors.InvalidRepeatableAnnotationNotApplicable(targetContainerType, on));
+                }
 
                 if (!chk.validateAnnotationDeferErrors(annoTree))
                     log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType);
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Apr 17 11:52:10 2015 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Apr 17 12:37:11 2015 +0200
@@ -410,6 +410,10 @@
 compiler.err.invalid.repeatable.annotation.repeated.and.container.present=\
     container {0} must not be present at the same time as the element it contains
 
+# 0: type, 1: symbol
+compiler.err.invalid.repeatable.annotation.not.applicable=\
+    container {0} is not applicable to element {1}
+
 # 0: name
 compiler.err.duplicate.class=\
     duplicate class: {0}
--- a/langtools/test/tools/javac/annotations/repeatingAnnotations/RepeatingTargetNotAllowed.out	Fri Apr 17 11:52:10 2015 +0200
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/RepeatingTargetNotAllowed.out	Fri Apr 17 12:37:11 2015 +0200
@@ -1,2 +1,2 @@
-RepeatingTargetNotAllowed.java:43:5: compiler.err.invalid.repeatable.annotation.incompatible.target: Foos, Foo
+RepeatingTargetNotAllowed.java:43:5: compiler.err.invalid.repeatable.annotation.not.applicable: Foos, f
 1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/NonApplicableRepeatingAnno.java	Fri Apr 17 12:37:11 2015 +0200
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+// key: compiler.err.invalid.repeatable.annotation.not.applicable
+
+import java.lang.annotation.*;
+
+@Repeatable(Foos.class)
+@interface Foo {}
+
+@Target(ElementType.ANNOTATION_TYPE)
+@interface Foos {
+    Foo[] value();
+}
+
+public class NonApplicableRepeatingAnno {
+    @Foo @Foo int f = 0;
+}