6975231: Regression test for 6881115 is failing with compiler output not matching expected output
authormcimadamore
Tue, 10 Aug 2010 14:53:19 +0100
changeset 6345 7d98c298aafd
parent 6344 f190fb7fdd2d
child 6346 0858e33944a6
6975231: Regression test for 6881115 is failing with compiler output not matching expected output Summary: missing symbols are collected in an HashSet which doesn't preserve ordering Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/test/tools/javac/annotations/6881115/T6881115.out
langtools/test/tools/javac/diags/examples/AnnotationMissingValues1.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Aug 10 14:52:34 2010 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Aug 10 14:53:19 2010 +0100
@@ -2120,8 +2120,12 @@
     public void validateAnnotation(JCAnnotation a) {
         if (a.type.isErroneous()) return;
 
-        // collect an inventory of the members
-        Set<MethodSymbol> members = new HashSet<MethodSymbol>();
+        // collect an inventory of the members (sorted alphabetically)
+        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;
              e != null;
              e = e.sibling)
@@ -2142,10 +2146,18 @@
         }
 
         // all the remaining ones better have default values
-        for (MethodSymbol m : members)
-            if (m.defaultValue == null && !m.type.isErroneous())
-                log.error(a.pos(), "annotation.missing.default.value",
-                          a.type, m.name);
+        ListBuffer<Name> missingDefaults = ListBuffer.lb();
+        for (MethodSymbol m : members) {
+            if (m.defaultValue == null && !m.type.isErroneous()) {
+                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
         // repeated values in its value member
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 10 14:52:34 2010 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 10 14:53:19 2010 +0100
@@ -42,7 +42,9 @@
 compiler.err.already.defined.this.unit=\
     {0} is already defined in this compilation unit
 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=\
     annotation not valid for a value of type {0}
 compiler.err.annotation.type.not.applicable=\
--- a/langtools/test/tools/javac/annotations/6881115/T6881115.out	Tue Aug 10 14:52:34 2010 +0100
+++ b/langtools/test/tools/javac/annotations/6881115/T6881115.out	Tue Aug 10 14:53:19 2010 +0100
@@ -1,6 +1,6 @@
 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: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:32: compiler.err.annotation.missing.default.value: B, b1
 5 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/AnnotationMissingValues1.java	Tue Aug 10 14:53:19 2010 +0100
@@ -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 { }