Mon, 24 Jan 2011 15:45:24 +0000
6569633: Varargs: parser error when varargs element type is an array
Summary: explicit error message when old-style array syntax is mixed with varargs
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon Jan 24 15:45:06 2011 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon Jan 24 15:45:24 2011 +0000 1.3 @@ -2168,8 +2168,11 @@ 1.4 JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type) { 1.5 int pos = S.pos(); 1.6 Name name = ident(); 1.7 - if ((mods.flags & Flags.VARARGS) == 0) 1.8 - type = bracketsOpt(type); 1.9 + if ((mods.flags & Flags.VARARGS) != 0 && 1.10 + S.token() == LBRACKET) { 1.11 + log.error(S.pos(), "varargs.and.old.array.syntax"); 1.12 + } 1.13 + type = bracketsOpt(type); 1.14 return toP(F.at(pos).VarDef(mods, name, type, null)); 1.15 } 1.16
2.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Mon Jan 24 15:45:06 2011 +0000 2.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Mon Jan 24 15:45:24 2011 +0000 2.3 @@ -266,6 +266,8 @@ 2.4 hexadecimal numbers must contain at least one hexadecimal digit 2.5 compiler.err.invalid.meth.decl.ret.type.req=\ 2.6 invalid method declaration; return type required 2.7 +compiler.err.varargs.and.old.array.syntax=\ 2.8 + legacy array notation not allowed on variable-arity parameter 2.9 2.10 compiler.err.label.already.in.use=\ 2.11 label {0} already in use
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/diags/examples/VarargsAndOldArraySyntax.java Mon Jan 24 15:45:24 2011 +0000 3.3 @@ -0,0 +1,28 @@ 3.4 +/* 3.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +// key: compiler.err.varargs.and.old.array.syntax 3.28 + 3.29 +class VarargsAndOldArraySyntax { 3.30 + void m1 (Integer... i[]) { } 3.31 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/varargs/6569633/T6569633.java Mon Jan 24 15:45:24 2011 +0000 4.3 @@ -0,0 +1,13 @@ 4.4 +/* 4.5 + * @test /nodynamiccopyright/ 4.6 + * @bug 6569633 4.7 + * @author mcimadamore 4.8 + * @summary Varargs: parser error when varargs element type is an array 4.9 + * @compile/fail/ref=T6569633.out -XDrawDiagnostics T6569633.java 4.10 + */ 4.11 + 4.12 +class T6569633 { 4.13 + void m1 (Integer... i[]) { } 4.14 + void m2 (Integer[]... i) { } 4.15 + void m3 (Integer[]... i[]) { } 4.16 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/varargs/6569633/T6569633.out Mon Jan 24 15:45:24 2011 +0000 5.3 @@ -0,0 +1,3 @@ 5.4 +T6569633.java:10:27: compiler.err.varargs.and.old.array.syntax 5.5 +T6569633.java:12:29: compiler.err.varargs.and.old.array.syntax 5.6 +2 errors