-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b03
-
x86
-
windows_xp
-
Verified
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b40)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b40, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Currrent javac implementation doesn't permit
in its parser to create an array of a inner class that have
a generic enclosing class.
see Foo example after :
inner = new Foo<?>.Inner[10];
or
inner = new Foo<Object>.Inner[10];
can't be parsed by the compiler.
This problem come from comments on the Scott Violet weblog :
(http://weblogs.java.net/blog/zixle/archive/2005/08/should_we_gener_1.html)
and i don't see why it's not syntactically and semantically correct.
Reading the JL3 grammar, it seems legal :
new Foo<?>.Inner[10] is :
'new'
ClassOrInterfaceType
(ClassOrInterfaceType(TypeName('Foo') TypeArguments('<?>')) '.'
Identifier('Inner'))
DimExprs('[10]')
so it's syntactically legal.
I think it semantically valid for the same reason that
new List<?>[10] is valid.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the Foo class.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
it compiles.
ACTUAL -
it doesn't compile.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
C:\eclipse\workspace\java-patch\src>javac Foo.java
Foo.java:11: '(' or '[' expected
inner = new Foo<?>.Inner[10];
^
1 error
---------- BEGIN SOURCE ----------
public class Foo<T> {
private T t;
private Foo<?>.Inner[] inner;
public Foo(T t) {
this.t = t;
inner = new Foo<?>.Inner[10];
}
private class Inner {
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use a raw type instead :
public class Foo<T> {
private T t;
private Foo<?>.Inner[] inner;
public Foo(T t) {
this.t = t;
inner = new Foo.Inner[10];
}
private class Inner {
}
}
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b40)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b40, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Currrent javac implementation doesn't permit
in its parser to create an array of a inner class that have
a generic enclosing class.
see Foo example after :
inner = new Foo<?>.Inner[10];
or
inner = new Foo<Object>.Inner[10];
can't be parsed by the compiler.
This problem come from comments on the Scott Violet weblog :
(http://weblogs.java.net/blog/zixle/archive/2005/08/should_we_gener_1.html)
and i don't see why it's not syntactically and semantically correct.
Reading the JL3 grammar, it seems legal :
new Foo<?>.Inner[10] is :
'new'
ClassOrInterfaceType
(ClassOrInterfaceType(TypeName('Foo') TypeArguments('<?>')) '.'
Identifier('Inner'))
DimExprs('[10]')
so it's syntactically legal.
I think it semantically valid for the same reason that
new List<?>[10] is valid.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the Foo class.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
it compiles.
ACTUAL -
it doesn't compile.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
C:\eclipse\workspace\java-patch\src>javac Foo.java
Foo.java:11: '(' or '[' expected
inner = new Foo<?>.Inner[10];
^
1 error
---------- BEGIN SOURCE ----------
public class Foo<T> {
private T t;
private Foo<?>.Inner[] inner;
public Foo(T t) {
this.t = t;
inner = new Foo<?>.Inner[10];
}
private class Inner {
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use a raw type instead :
public class Foo<T> {
private T t;
private Foo<?>.Inner[] inner;
public Foo(T t) {
this.t = t;
inner = new Foo.Inner[10];
}
private class Inner {
}
}
- relates to
-
JDK-6481655 Parser confused by combination of parens and explicit type args
- Closed
-
JDK-6486430 Compiler fails to reject access to static member in parameterized type
- Closed