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

Tue, 10 Aug 2010 14:53:19 +0100

author
mcimadamore
date
Tue, 10 Aug 2010 14:53:19 +0100
changeset 632
ea1930f4b789
parent 631
a2d8c7071f24
child 633
c04ae2714f52

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

src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/resources/compiler.properties file | annotate | diff | comparison | revisions
test/tools/javac/annotations/6881115/T6881115.out file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/AnnotationMissingValues1.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Aug 10 14:52:34 2010 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Aug 10 14:53:19 2010 +0100
     1.3 @@ -2120,8 +2120,12 @@
     1.4      public void validateAnnotation(JCAnnotation a) {
     1.5          if (a.type.isErroneous()) return;
     1.6  
     1.7 -        // collect an inventory of the members
     1.8 -        Set<MethodSymbol> members = new HashSet<MethodSymbol>();
     1.9 +        // collect an inventory of the members (sorted alphabetically)
    1.10 +        Set<MethodSymbol> members = new TreeSet<MethodSymbol>(new Comparator<Symbol>() {
    1.11 +            public int compare(Symbol t, Symbol t1) {
    1.12 +                return t.name.compareTo(t1.name);
    1.13 +            }
    1.14 +        });
    1.15          for (Scope.Entry e = a.annotationType.type.tsym.members().elems;
    1.16               e != null;
    1.17               e = e.sibling)
    1.18 @@ -2142,10 +2146,18 @@
    1.19          }
    1.20  
    1.21          // all the remaining ones better have default values
    1.22 -        for (MethodSymbol m : members)
    1.23 -            if (m.defaultValue == null && !m.type.isErroneous())
    1.24 -                log.error(a.pos(), "annotation.missing.default.value",
    1.25 -                          a.type, m.name);
    1.26 +        ListBuffer<Name> missingDefaults = ListBuffer.lb();
    1.27 +        for (MethodSymbol m : members) {
    1.28 +            if (m.defaultValue == null && !m.type.isErroneous()) {
    1.29 +                missingDefaults.append(m.name);
    1.30 +            }
    1.31 +        }
    1.32 +        if (missingDefaults.nonEmpty()) {
    1.33 +            String key = (missingDefaults.size() > 1)
    1.34 +                    ? "annotation.missing.default.value.1"
    1.35 +                    : "annotation.missing.default.value";
    1.36 +            log.error(a.pos(), key, a.type, missingDefaults);
    1.37 +        }
    1.38  
    1.39          // special case: java.lang.annotation.Target must not have
    1.40          // repeated values in its value member
     2.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 10 14:52:34 2010 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 10 14:53:19 2010 +0100
     2.3 @@ -42,7 +42,9 @@
     2.4  compiler.err.already.defined.this.unit=\
     2.5      {0} is already defined in this compilation unit
     2.6  compiler.err.annotation.missing.default.value=\
     2.7 -    annotation {0} is missing {1}
     2.8 +    annotation {0} is missing value for the attribute {1}
     2.9 +compiler.err.annotation.missing.default.value.1=\
    2.10 +    annotation {0} is missing values for attributes {1}
    2.11  compiler.err.annotation.not.valid.for.type=\
    2.12      annotation not valid for a value of type {0}
    2.13  compiler.err.annotation.type.not.applicable=\
     3.1 --- a/test/tools/javac/annotations/6881115/T6881115.out	Tue Aug 10 14:52:34 2010 +0100
     3.2 +++ b/test/tools/javac/annotations/6881115/T6881115.out	Tue Aug 10 14:53:19 2010 +0100
     3.3 @@ -1,6 +1,6 @@
     3.4  T6881115.java:10:30: compiler.err.duplicate.annotation.member.value: b2, B
     3.5  T6881115.java:10:19: compiler.err.annotation.missing.default.value: B, b1
     3.6 -T6881115.java:11:26: compiler.err.annotation.missing.default.value: B, b1
     3.7 +T6881115.java:11:26: compiler.err.annotation.missing.default.value.1: B, b1,b2
     3.8  T6881115.java:11:43: compiler.err.duplicate.annotation.member.value: b2, B
     3.9  T6881115.java:11:32: compiler.err.annotation.missing.default.value: B, b1
    3.10  5 errors
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/diags/examples/AnnotationMissingValues1.java	Tue Aug 10 14:53:19 2010 +0100
     4.3 @@ -0,0 +1,32 @@
     4.4 +/*
     4.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +
    4.27 +// key: compiler.err.annotation.missing.default.value.1
    4.28 +
    4.29 +@interface Anno {
    4.30 +    String a();
    4.31 +    String b();
    4.32 +}
    4.33 +
    4.34 +@Anno
    4.35 +class AnnotationMissingValue { }

mercurial