Mercurial > hg > release > icedtea7-forest-2.4 > langtools
changeset 656:27bae58329d5
6976649: javac does not enforce required annotation elements in arrays
Summary: type annotation should take advantage of recursive annotation checking
Reviewed-by: jjg
author | mcimadamore |
---|---|
date | Mon, 16 Aug 2010 14:56:23 +0100 |
parents | c04ae2714f52 |
children | dc550520ed6f |
files | src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/comp/Check.java test/tools/javac/annotations/6881115/T6881115.java test/tools/javac/annotations/6881115/T6881115.out test/tools/javac/annotations/pos/TrailingComma.java |
diffstat | 5 files changed, 29 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Aug 12 19:59:10 2010 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Aug 16 14:56:23 2010 +0100 @@ -696,9 +696,11 @@ // ensure that annotation method does not clash with members of Object/Annotation chk.validateAnnotationMethod(tree.pos(), m); - // if default value is an annotation, check it is a well-formed - // annotation value (e.g. no duplicate values, no missing values, etc.) - chk.validateAnnotationDefaultValue(tree.defaultValue); + if (tree.defaultValue != null) { + // if default value is an annotation, check it is a well-formed + // annotation value (e.g. no duplicate values, no missing values, etc.) + chk.validateAnnotationTree(tree.defaultValue); + } } for (List<JCExpression> l = tree.thrown; l.nonEmpty(); l = l.tail)
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Aug 12 19:59:10 2010 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Mon Aug 16 14:56:23 2010 +0100 @@ -25,6 +25,7 @@ package com.sun.tools.javac.comp; +import com.sun.source.tree.AssignmentTree; import java.util.*; import java.util.Set; @@ -1930,20 +1931,17 @@ **************************************************************************/ /** - * Validate annotations in default values + * Recursively validate annotations values */ - void validateAnnotationDefaultValue(JCTree defaultValue) { - class DefaultValueValidator extends TreeScanner { + void validateAnnotationTree(JCTree tree) { + class AnnotationValidator extends TreeScanner { @Override public void visitAnnotation(JCAnnotation tree) { super.visitAnnotation(tree); validateAnnotation(tree); } } - // defaultValue may be null if an error occurred, so don't bother validating it - if (defaultValue != null) { - defaultValue.accept(new DefaultValueValidator()); - } + tree.accept(new AnnotationValidator()); } /** Annotation types are restricted to primitives, String, an @@ -2009,7 +2007,7 @@ /** Check an annotation of a symbol. */ public void validateAnnotation(JCAnnotation a, Symbol s) { - validateAnnotation(a); + validateAnnotationTree(a); if (!annotationApplicable(a, s)) log.error(a.pos(), "annotation.type.not.applicable"); @@ -2023,7 +2021,7 @@ public void validateTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) { if (a.type == null) throw new AssertionError("annotation tree hasn't been attributed yet: " + a); - validateAnnotation(a); + validateAnnotationTree(a); if (!isTypeAnnotation(a, isTypeParameter)) log.error(a.pos(), "annotation.type.not.applicable"); @@ -2141,8 +2139,6 @@ if (!members.remove(m)) log.error(assign.lhs.pos(), "duplicate.annotation.member.value", m.name, a.type); - if (assign.rhs.getTag() == ANNOTATION) - validateAnnotation((JCAnnotation)assign.rhs); } // all the remaining ones better have default values
--- a/test/tools/javac/annotations/6881115/T6881115.java Thu Aug 12 19:59:10 2010 -0700 +++ b/test/tools/javac/annotations/6881115/T6881115.java Mon Aug 16 14:56:23 2010 +0100 @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6881115 + * @bug 6881115 6976649 * @summary javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException * @author mcimadamore * @compile/fail/ref=T6881115.out -XDrawDiagnostics T6881115.java @@ -14,5 +14,7 @@ String b1(); int b2(); } -@A -class T6881115 {} +@A(b = @B(b2 = 1, b2 = 2), + b_arr = {@B(), @B(b2 = 1, b2 = 2)}) +class T6881115<@A(b = @B(b2 = 1, b2 = 2), + b_arr = {@B(), @B(b2 = 1, b2 = 2)}) X> {}
--- a/test/tools/javac/annotations/6881115/T6881115.out Thu Aug 12 19:59:10 2010 -0700 +++ b/test/tools/javac/annotations/6881115/T6881115.out Mon Aug 16 14:56:23 2010 +0100 @@ -3,4 +3,14 @@ T6881115.java:11:26: compiler.err.annotation.missing.default.value.1: B, b1,b2 T6881115.java:11:43: compiler.err.duplicate.annotation.member.value: b2, B T6881115.java:11:32: compiler.err.annotation.missing.default.value: B, b1 -5 errors +T6881115.java:17:19: compiler.err.duplicate.annotation.member.value: b2, B +T6881115.java:17:8: compiler.err.annotation.missing.default.value: B, b1 +T6881115.java:18:13: compiler.err.annotation.missing.default.value.1: B, b1,b2 +T6881115.java:18:30: compiler.err.duplicate.annotation.member.value: b2, B +T6881115.java:18:19: compiler.err.annotation.missing.default.value: B, b1 +T6881115.java:19:34: compiler.err.duplicate.annotation.member.value: b2, B +T6881115.java:19:23: compiler.err.annotation.missing.default.value: B, b1 +T6881115.java:20:28: compiler.err.annotation.missing.default.value.1: B, b1,b2 +T6881115.java:20:45: compiler.err.duplicate.annotation.member.value: b2, B +T6881115.java:20:34: compiler.err.annotation.missing.default.value: B, b1 +15 errors
--- a/test/tools/javac/annotations/pos/TrailingComma.java Thu Aug 12 19:59:10 2010 -0700 +++ b/test/tools/javac/annotations/pos/TrailingComma.java Mon Aug 16 14:56:23 2010 +0100 @@ -36,7 +36,7 @@ } -@TestAnnotation({@SuppressWarnings(), +@TestAnnotation({@SuppressWarnings({}), @SuppressWarnings({"Beware the ides of March.",}), @SuppressWarnings({"Look both ways", "Before Crossing",}), }) public class TrailingComma {