6975231: Regression test for 6881115 is failing with compiler output not matching expected output

Missing symbols are collected in an HashSet which doesn't preserve ordering

Reviewed-by: jjg
This commit is contained in:
Maurizio Cimadamore 2010-08-10 14:53:19 +01:00
parent 132dde52c3
commit 23a89dba04
4 changed files with 54 additions and 8 deletions

View file

@ -2120,8 +2120,12 @@ public class Check {
public void validateAnnotation(JCAnnotation a) { public void validateAnnotation(JCAnnotation a) {
if (a.type.isErroneous()) return; if (a.type.isErroneous()) return;
// collect an inventory of the members // collect an inventory of the members (sorted alphabetically)
Set<MethodSymbol> members = new HashSet<MethodSymbol>(); Set<MethodSymbol> members = new TreeSet<MethodSymbol>(new Comparator<Symbol>() {
public int compare(Symbol t, Symbol t1) {
return t.name.compareTo(t1.name);
}
});
for (Scope.Entry e = a.annotationType.type.tsym.members().elems; for (Scope.Entry e = a.annotationType.type.tsym.members().elems;
e != null; e != null;
e = e.sibling) e = e.sibling)
@ -2142,10 +2146,18 @@ public class Check {
} }
// all the remaining ones better have default values // all the remaining ones better have default values
for (MethodSymbol m : members) ListBuffer<Name> missingDefaults = ListBuffer.lb();
if (m.defaultValue == null && !m.type.isErroneous()) for (MethodSymbol m : members) {
log.error(a.pos(), "annotation.missing.default.value", if (m.defaultValue == null && !m.type.isErroneous()) {
a.type, m.name); missingDefaults.append(m.name);
}
}
if (missingDefaults.nonEmpty()) {
String key = (missingDefaults.size() > 1)
? "annotation.missing.default.value.1"
: "annotation.missing.default.value";
log.error(a.pos(), key, a.type, missingDefaults);
}
// special case: java.lang.annotation.Target must not have // special case: java.lang.annotation.Target must not have
// repeated values in its value member // repeated values in its value member

View file

@ -42,7 +42,9 @@ compiler.err.already.defined.static.single.import=\
compiler.err.already.defined.this.unit=\ compiler.err.already.defined.this.unit=\
{0} is already defined in this compilation unit {0} is already defined in this compilation unit
compiler.err.annotation.missing.default.value=\ compiler.err.annotation.missing.default.value=\
annotation {0} is missing {1} annotation {0} is missing value for the attribute {1}
compiler.err.annotation.missing.default.value.1=\
annotation {0} is missing values for attributes {1}
compiler.err.annotation.not.valid.for.type=\ compiler.err.annotation.not.valid.for.type=\
annotation not valid for a value of type {0} annotation not valid for a value of type {0}
compiler.err.annotation.type.not.applicable=\ compiler.err.annotation.type.not.applicable=\

View file

@ -1,6 +1,6 @@
T6881115.java:10:30: compiler.err.duplicate.annotation.member.value: b2, B T6881115.java:10:30: compiler.err.duplicate.annotation.member.value: b2, B
T6881115.java:10:19: compiler.err.annotation.missing.default.value: B, b1 T6881115.java:10:19: compiler.err.annotation.missing.default.value: B, b1
T6881115.java:11:26: compiler.err.annotation.missing.default.value: B, b1 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:43: compiler.err.duplicate.annotation.member.value: b2, B
T6881115.java:11:32: compiler.err.annotation.missing.default.value: B, b1 T6881115.java:11:32: compiler.err.annotation.missing.default.value: B, b1
5 errors 5 errors

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2010, 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.annotation.missing.default.value.1
@interface Anno {
String a();
String b();
}
@Anno
class AnnotationMissingValue { }