8043984: Confusing (incorrect) error message on repeatable annotations

Adjusted error mesage for repeating annotations

Reviewed-by: jfranck, dlsmith
This commit is contained in:
Andreas Lundblad 2015-04-17 12:37:11 +02:00
parent e17a42c26a
commit 868bdb35b2
4 changed files with 48 additions and 4 deletions

View File

@ -31,6 +31,7 @@ import com.sun.tools.javac.code.Attribute.TypeCompound;
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 @@ public class Annotate {
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);

View File

@ -410,6 +410,10 @@ compiler.err.invalid.repeatable.annotation.incompatible.target=\
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}

View File

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

View File

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