### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/ClassLiteralAccess.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ClassLiteralAccess.java,v retrieving revision 1.50 diff -u -r1.50 ClassLiteralAccess.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ClassLiteralAccess.java 27 Jun 2008 16:03:55 -0000 1.50 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ClassLiteralAccess.java 22 Jul 2010 05:27:25 -0000 @@ -77,6 +77,16 @@ this.constant = Constant.NotAConstant; if ((this.targetType = this.type.resolveType(scope, true /* check bounds*/)) == null) return null; + + /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=320463 + https://bugs.eclipse.org/bugs/show_bug.cgi?id=312076 + JLS3 15.8.2 forbids the type named in the class literal expression from being a parameterized type. + And the grammar in 18.1 disallows (where X and Y are some concrete types) constructs of the form + Outer.class, Outer.Inner.class, Outer.Inner.class, Outer.Inner.class etc. + Corollary wise, we should resolve the type of the class literal expression to be a raw type as + class literals exist only for the raw underlying type. + */ + this.targetType = scope.environment().convertToRawType(this.targetType, true /* force conversion of enclosing types*/); if (this.targetType.isArrayType()) { ArrayBinding arrayBinding = (ArrayBinding) this.targetType; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v retrieving revision 1.823 diff -u -r1.823 GenericTypeTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 22 Jul 2010 04:25:34 -0000 1.823 +++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 22 Jul 2010 05:27:49 -0000 @@ -50557,4 +50557,79 @@ "Zork cannot be resolved to a type\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320463 +public void test1465() { + this.runNegativeTest( + new String[] { + "Outer.java", + "public class Outer {\n"+ + " class Cell {\n"+ + " final T value;\n"+ + " Cell(T value) {\n"+ + " this.value = value;\n"+ + " }\n"+ + " }\n"+ + " Class.Cell> cellClass = Cell.class;\n"+ + " {\n"+ + " this.cellClass = Cell.class;\n"+ + " this.cellClass = Outer.Cell.class;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " Outer.Cell intCell = new Outer().new Cell(314);\n"+ + " Outer.Cell strCell = new Outer().cellClass.cast(intCell);\n"+ + " String val = strCell.value; // ClassCastException\n"+ + " System.out.println(val);\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in Outer.java (at line 8)\n" + + " Class.Cell> cellClass = Cell.class;\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class.Cell>\n" + + "----------\n" + + "2. ERROR in Outer.java (at line 10)\n" + + " this.cellClass = Cell.class;\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class.Cell>\n" + + "----------\n" + + "3. ERROR in Outer.java (at line 11)\n" + + " this.cellClass = Outer.Cell.class;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class.Cell>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312076 +public void test1466() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public abstract static class Base> {\n" + + " public Base(Class sClass) {\n" + + " Class theClass = sClass;\n" + + " System.out.println(theClass);\n" + + " System.out.println(sClass);\n" + + " }\n" + + " }\n" + + " public class Arr extends Base {\n" + + " public Arr() { \n" + + " super(Arr.class);\n" + + " System.out.println(Arr.class);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " X.Arr a = x.new Arr();\n" + + " System.out.println(a);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " super(Arr.class);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The constructor X.Base.Arr>(Class) is undefined\n" + + "----------\n"); +} } \ No newline at end of file