Name: nt126004 Date: 09/19/2002
FULL PRODUCT VERSION :
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version
5.00.2195]
A DESCRIPTION OF THE PROBLEM :
The syntactic grammar is given by JLS as follows.
Primary:
PrimaryNoNewArray
ArrayCreationExpression
PrimaryNoNewArray:
Literal
Type .
class
void . class
this
ClassName.this
( Expression )
ClassInstanceCreationExpression
FieldAccess
MethodInvocation
ArrayAccess
ClassInstanceCreationExpression:
new
ClassOrInterfaceType ( ArgumentListopt ) ClassBody opt
Primary.new
Identifier ( ArgumentListopt ) ClassBody opt
It means the
following expression is an error.
(from Line 153 of java/util/logging/LogManager.java)
manager.new RootLogger();
Also,
ArrayCreationExpression:
new
PrimitiveType DimExprs Dimsopt
new TypeName DimExprs Dimsopt
new
PrimitiveType Dims ArrayInitializer
new TypeName Dims
ArrayInitializer
ArrayAccess:
ExpressionName [ Expression ]
PrimaryNoNewArray [ Expression ]
means the following expression is
error. (from Bug Id 4321177)
new char[] { 'B', 'u', 'g' }[i]
The
state of 4321177 is "closed, not a bug," but it is a bug. The
evaluation of 4321177 shows a grammar accepting the expression. But,
the grammer is given in Chapter 18 of JLS. Section 2.3 of JLS says
> The syntactic grammar for the Java programming language is given in
> Chapters 4, 6?]10, 14, and 15. This grammar has tokens defined by the
> lexical grammar as its terminal symbols. It defines a set of
> productions, starting from the goal symbol CompilationUnit (??7.3), that
> describe how sequences of tokens can form syntactically correct
> programs.
Only the grammer given in Chapters 4, 6?]10, 14, and 15
describes the syntactic correctness of programs.
I think we can have the following consensus:
(1) JLS gives two grammars. One is defined in Chapter 4, 6-10, 14, and
15. The other is defined in Chapter 18.
(2) The former rejects the expression "identifier.new ...", but the
latter accepts it.
(3) Either the former or the latter define the correct syntactic
grammar. If the former is correct, every Java compiler (and Java
language tool) should reject the expression. If the latter is
correct, every one should accept it in syntactic processes.
(4) For compatibility, it is important to clear which is correct.
> The grammar presented in chapter 18 of the JLS is an acceptable grammar.
You think the latter is the better choice. But, I think the former is
the correct grammar for some reasons:
(1) The semantics of class instance creation expressions explicitly
demands the former. In Section 15.9,
> Class instance creation expressions have two forms:
> - Unqualified class instance creation expressions begin with the
> keyword new.
> - Qualified class instance creation expressions begin with a Primary.
Here, a Primary doesn't include a single identifier.
And, in 15.9.1,
> - If the class instance creation expression is an unqualified
> class instance creation expression, ...
> - Otherwise, the class instance creation expression is a qualified
> class instance creation expression.
(2) It is often said that the former is "the grammar" but the latter is
"a grammar." In Chapter 1, "Chapter 2 describes grammars and the
notation used to present *the* lexical and syntactic grammars for
the language." "Chapter 18 presents *a* syntactic grammar for the
language." In Chapter 2, "This chapter describes the context-free
grammars used in this specification to define *the* lexical and
syntactic structure of a program." In 2.3, "*The* syntactic grammar
for the Java programming language is given in Chapters 4, 6-10, 14,
and 15." In Chapter 18, "This chapter presents *a* grammar for the
Java programming language."
(3) Again,
> The
> state of 4321177 is "closed, not a bug," but it is a bug. The
> evaluation of 4321177 shows a grammer accepting the expression. But,
> the grammer is given in Chapter 18 of JLS. Section 2.3 of JLS says
>
> > The syntactic grammar for the Java programming language is given in
> > Chapters 4, 6?]10, 14, and 15. This grammar has tokens defined by the
> > lexical grammar as its terminal symbols. It defines a set of
> > productions, starting from the goal symbol CompilationUnit (??7.3), that
> > describe how sequences of tokens can form syntactically correct
> > programs.
>
> Only the grammer given in Chapters 4, 6?]10, 14, and 15
> describes the syntactic correctness of programs.
(4) The latter is a only basis, so says nothing about the correct grammar.
> Chapter 18 states :
> The grammar presented piecemeal in the preceding chapters is much
> better for exposition, but it is not ideally suited as a basis for a
> parser. The grammar presented in this chapter is the basis for the
> reference implementation.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile java/util/logging/LogManager.java and the following
ArrayBug.
EXPECTED VERSUS ACTUAL BEHAVIOR :
javac rejects the errors with error messages.
(Or, an update of JLS to
accept the expressions. It will be better for Java 1.5)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No message.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
(1) java/util/logging/LogManager.java (1.20 01/12/03)
(2) (from Bug Id 4321177)
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);
}
}
---------- END SOURCE ----------
(Review ID: 164525)
======================================================================