6337964: should ignore last comma in annotation array

Thu, 24 Sep 2009 16:00:03 -0700

author
darcy
date
Thu, 24 Sep 2009 16:00:03 -0700
changeset 417
d0f541480556
parent 416
c287d51c57da
child 418
4776a869fdfa

6337964: should ignore last comma in annotation array
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/parser/JavacParser.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/pos/TrailingComma.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Wed Sep 23 19:15:04 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Sep 24 16:00:03 2009 -0700
     1.3 @@ -2236,7 +2236,7 @@
     1.4  
     1.5      /* AnnotationValue          = ConditionalExpression
     1.6       *                          | Annotation
     1.7 -     *                          | "{" [ AnnotationValue { "," AnnotationValue } ] "}"
     1.8 +     *                          | "{" [ AnnotationValue { "," AnnotationValue } ] [","] "}"
     1.9       */
    1.10      JCExpression annotationValue() {
    1.11          int pos;
    1.12 @@ -2253,7 +2253,7 @@
    1.13                  buf.append(annotationValue());
    1.14                  while (S.token() == COMMA) {
    1.15                      S.nextToken();
    1.16 -                    if (S.token() == RPAREN) break;
    1.17 +                    if (S.token() == RBRACE) break;
    1.18                      buf.append(annotationValue());
    1.19                  }
    1.20              }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/annotations/pos/TrailingComma.java	Thu Sep 24 16:00:03 2009 -0700
     2.3 @@ -0,0 +1,43 @@
     2.4 +/*
     2.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug 6337964
    2.30 + * @summary javac incorrectly disallows trailing comma in annotation arrays
    2.31 + * @author darcy
    2.32 + * @compile TrailingComma.java
    2.33 + */
    2.34 +
    2.35 +import java.lang.annotation.*;
    2.36 +
    2.37 +@interface TestAnnotation {
    2.38 +    SuppressWarnings[] value() default {@SuppressWarnings({"",})};
    2.39 +}
    2.40 +
    2.41 +
    2.42 +@TestAnnotation({@SuppressWarnings(),
    2.43 +                 @SuppressWarnings({"Beware the ides of March.",}),
    2.44 +                 @SuppressWarnings({"Look both ways", "Before Crossing",}), })
    2.45 +public class TrailingComma {
    2.46 +}

mercurial