Name: stC104175 Date: 03/13/2000
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
It should not be possible to follow the declaration of an anonymous
array by an array access, due to the following production rules:
Primary:
PrimaryNoNewArray
ArrayCreationExpression
PrimaryNoNewArray:
Literal
this
( Expression )
ClassInstanceCreationExpression
FieldAccess
MethodInvocation
ArrayAccess
ArrayAccess:
Name [ Expression ]
PrimaryNoNewArray [ Expression ]
ArrayCreationExpression:
new PrimitiveType DimExprs Dimsopt
new ClassOrInterfaceType DimExprs Dimsopt
new Type Dims ArrayInitializer
Because an anonymous array is created in an ArrayCreationExpression,
but an array access is performed on a PrimaryNewArray, the two
constructs may not be mixed. But the code below compiles under javac:
public class ArrayBug {
public static void main(String args[]) {
for (int i = 0; i < 3; i++) {
System.out.print(new char[] { 'B', 'u', 'g' }[i]);
}
System.out.println(new char[] { 'O', 'K' }.length);
}
}
The Jikes compiler correctly detects the error in the code.
Both compilers correctly compile the code when parenthesis
are placed around the anonymous array creation.
Note that it is okay to access the length field of an
anonymous array without using the parenthesis, as in the
last line of the program (see Bug Id 4091602).
(Review ID: 102221)
======================================================================