JDK-6569404 : Regression: Cannot instantiate an inner class of a type variable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-06-13
  • Updated: 2012-04-06
  • Resolved: 2012-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b70Fixed
Related Reports
Relates :  
Relates :  
Description
I am wondering if the following program is correct or wrong.
Javac 1.5 did allow it, Javac 1.6 rejects it.

The spec seems to imply it is legitimate: In 4.4, it claims:
"The members of a type variable X with bound T & I1 ... In are the members
of the intersection type (��4.9) T & I1 ... In appearing at the point where
the type variable is declared."

Then in 4.9, last bullet:
"��� Then the intersection type has the same members as a class type (��8)
with an empty body, direct superclass Ck and direct superinterfaces IT1 , ..., ITn,
declared in the same package in which the intersection type appears."

-------------

public class Outer {
  public class Inner {}
}

class ATest<T extends Outer> {
   public ATest() {
      T instance = makeInstance();
      Outer.Inner peq = instance.new Inner(); // javac 1.6 error: "cannot select from a type variable"
   }

   private T makeInstance() {
      return (T) new Outer();
   }
}

Comments
SUGGESTED FIX A webrev for this fix is available at the following URL: http://hg.openjdk.java.net/jdk7/tl/langtools/rev/13902c0c9b83
11-08-2009

EVALUATION The bug has been introduced by fix of 6359951 - where we wanted to reject programs like: class Foo { class C<T> { public static Class classOfT = T.getClass();} class D<T> { } class E<T> extends D<T.classOfT> { } } E's type parameter T has no bound so T.classOfT makes no sense for D's type parameter. The example in this CR does have a bound. I see no JLS issue. The fix for 6359951 rejected far too much.
11-08-2009