JDK-4903103 : Can't compile subclasses of inner classes
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.0,1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8,windows_xp
  • CPU: generic,x86
  • Submitted: 2003-08-07
  • Updated: 2006-03-15
  • Resolved: 2006-02-18
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 6
6 b73Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
Name: rmT116609			Date: 08/07/2003


FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

FULL OS VERSION :
Microsoft Windows XP version 5.1.2600

A DESCRIPTION OF THE PROBLEM :
J2SE 1.4.2's javac will not compile classes that have doubly-nested inner subclasses, such as the following test case:

class InnerClassBugTestCase
{
    private class InnerSuperclass extends InnerClassBugTestCase
    {
    }

    private class InnerSubclass extends InnerSuperclass
    {
    }
}

The error message provided is:

InnerClassBugTestCase.java:7: cannot reference this before supertype constructor has been called
    private class InnerSubclass extends InnerSuperclass

J2SE 1.4.2-beta and J2SE 1.4.1_03's version of javac compiles the class without errors or warnings.

REGRESSION.  Last worked in version mantis-beta

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a text containing the following Java code:

class InnerClassBugTestCase
{
    private class InnerSuperclass extends InnerClassBugTestCase
    {
    }

    private class InnerSubclass extends InnerSuperclass
    {
    }
}

Save the file as InnerClassBugTestCase.java.

Attempt to compile InnerClassBugTestCase.java using J2SE 1.4.2's javac compiler: javac InnerClassBugTestCase.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
javac would compile the class into InnerClassBugTestCase.class.
ACTUAL -
javac did not compile the class, providing an error message that does not seem to apply.



ERROR MESSAGES/STACK TRACES THAT OCCUR :
InnerClassBugTestCase.java:7: cannot reference this before supertype constructor has been called
    private class InnerSubclass extends InnerSuperclass

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class InnerClassBugTestCase
{
    private class InnerSuperclass extends InnerClassBugTestCase
    {
    }

    private class InnerSubclass extends InnerSuperclass
    {
    }
}
---------- END SOURCE ----------

Release Regression From : mantis-beta
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 189935) 
======================================================================
###@###.### 10/25/04 21:44 GMT

Comments
SUGGESTED FIX Webrev of changes: http://sa.sfbay/projects/langtools/bugid_summary.pl?bugid=4903103
14-02-2006

SUGGESTED FIX Resolve.resolveImplicitThis should ignore inaccessible members.
30-11-2005

EVALUATION InnerSuperclass is a private class and should not be inherited by InnerSubclass. As InnerSuperclass isn't a member of InnerSubclass InnerSubclass.this is not the enclosing instance. Instead, the search will have to continue outwards and locate InnerClassBugTestCase.this as the enclosing instance.
30-11-2005

EVALUATION An incorrect fix for this bug was backed out of Mustang and 5.0u5. The previous incorrect evaluation has been removed to avoid confusion.
30-11-2005

WORK AROUND class InnerClassBugTestCase { private class InnerSuperclass extends InnerClassBugTestCase {} private class InnerSubclass extends InnerSuperclass { InnerSubclass() { InnerClassBugTestCase.this.super(); // use qualified superclass constructor } } } ###@###.### 2005-03-18 07:56:47 GMT
18-03-2005

SUGGESTED FIX Deleted incorrect fix.
17-03-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon mustang
07-09-2004

EVALUATION The code should be equivalent to this working code: class InnerClassBugTestCase { InnerClassBugTestCase() { super(); } private class InnerSuperclass extends InnerClassBugTestCase { private InnerSuperclass() { super(); } } private class InnerSubclass extends InnerSuperclass { private InnerSubclass() { (InnerClassBugTestCase.this).super(); //! } } } ###@###.### 2003-08-07
07-08-2003