OpenJDK / jdk / jdk12
changeset 3997:35250de1d4ea
6337964: should ignore last comma in annotation array
Reviewed-by: jjg
author | darcy |
---|---|
date | Thu, 24 Sep 2009 16:00:03 -0700 |
parents | dc676a9093b3 |
children | c66be272f350 |
files | langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java langtools/test/tools/javac/annotations/pos/TrailingComma.java |
diffstat | 2 files changed, 45 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Sep 23 19:15:04 2009 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Sep 24 16:00:03 2009 -0700 @@ -2236,7 +2236,7 @@ /* AnnotationValue = ConditionalExpression * | Annotation - * | "{" [ AnnotationValue { "," AnnotationValue } ] "}" + * | "{" [ AnnotationValue { "," AnnotationValue } ] [","] "}" */ JCExpression annotationValue() { int pos; @@ -2253,7 +2253,7 @@ buf.append(annotationValue()); while (S.token() == COMMA) { S.nextToken(); - if (S.token() == RPAREN) break; + if (S.token() == RBRACE) break; buf.append(annotationValue()); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/pos/TrailingComma.java Thu Sep 24 16:00:03 2009 -0700 @@ -0,0 +1,43 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6337964 + * @summary javac incorrectly disallows trailing comma in annotation arrays + * @author darcy + * @compile TrailingComma.java + */ + +import java.lang.annotation.*; + +@interface TestAnnotation { + SuppressWarnings[] value() default {@SuppressWarnings({"",})}; +} + + +@TestAnnotation({@SuppressWarnings(), + @SuppressWarnings({"Beware the ides of March.",}), + @SuppressWarnings({"Look both ways", "Before Crossing",}), }) +public class TrailingComma { +}