Name: ngR10089 Date: 01/29/2004
The latest spec of "Adding Generics to the Java Programming Language: Public
Draft Specification, Version 1.0", 5.1 reads:
"5.1 Class Instance Creation Expressions
. . .
Syntax (see JLS, Sec. 15.9)
ClassInstanceCreationExpression ::= new TypeArgumentsOpt
ClassOrInterfaceType TypeArgumentsOpt
( ArgumentListOpt ) ClassBodyOpt
| Primary.TypeArgumentsOpt new
Identifier TypeArgumentsOpt
( ArgumentListOpt ) ClassBodyOpt"
However javac (jdk1.5.0-b35) does not compile tests below.
--------------- test1 compilation-------------
> javac -d . -source 1.5 test1.java
An exception has occurred in the compiler (1.5.0-beta2). Please file a bug at
the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi) after
checking the Bug Parade for duplicates. Include your program and the following
diagnostic in your report. Thank you.
java.lang.NullPointerException
at com.sun.tools.javac.comp.Flow.visitNewClass(Flow.java:1105)
at com.sun.tools.javac.tree.Tree$NewClass.accept(Tree.java:841)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:34)
at com.sun.tools.javac.comp.Flow.scanExpr(Flow.java:500)
at com.sun.tools.javac.comp.Flow.visitVarDef(Flow.java:725)
at com.sun.tools.javac.tree.Tree$VarDef.accept(Tree.java:511)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:34)
at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:484)
at com.sun.tools.javac.comp.Flow.scanStats(Flow.java:492)
at com.sun.tools.javac.comp.Flow.visitBlock(Flow.java:732)
at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:540)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:34)
at com.sun.tools.javac.comp.Flow.scanStat(Flow.java:484)
at com.sun.tools.javac.comp.Flow.visitMethodDef(Flow.java:684)
at com.sun.tools.javac.tree.Tree$MethodDef.accept(Tree.java:482)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:34)
at com.sun.tools.javac.comp.Flow.visitClassDef(Flow.java:624)
at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:438)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:34)
at com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:1223)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:420)
at com.sun.tools.javac.main.Main.compile(Main.java:587)
at com.sun.tools.javac.main.Main.compile(Main.java:539)
at com.sun.tools.javac.Main.compile(Main.java:44)
at com.sun.tools.javac.Main.main(Main.java:35)
--------------- test2 compilation-------------
> javac -d . -source 1.5 test2.java
test2.java:17: cannot find symbol
symbol : constructor <java.lang.String>cl_a(java.lang.String)
location: class p.cl_a
cl_a p1 = new <String> cl_a("Test");
^
1 error
--------------- test1.java-------------
package p;
import java.io.PrintStream;
class cl_a<A> {
A value;
Object ob;
<T> cl_a(T val, A p2) {
ob = val;
value = p2;
}
Number getNumber() {
return new Short((short)2);
}
}
public class test1 {
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[],PrintStream out) {
cl_a<Integer> p1 = new <String> cl_a<Integer>("Test",new Integer(11)) {
Number getNumber() {
return new Short((short)1);
}
};
out.println(p1.getNumber());
return 0/*STATUS_PASSED*/;
}
}
---------------------------------------
--------------- test2.java-------------
package p;
import java.io.PrintStream;
class cl_a<A> {
A value;
Object ob;
<T> cl_a(T val) {
ob = val;
}
}
public class test2 {
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[],PrintStream out) {
cl_a p1 = new <String> cl_a("Test");
out.println(p1.value);
out.println(p1.ob);
return 0/*STATUS_PASSED*/;
}
}
---------------------------------------
New JCK tests
lang/EXPR/expr670/expr67003m0/expr67003m0.html
lang/EXPR/expr670/expr67003m1/expr67003m1.html
fail due to this bug.
======================================================================