JDK-7017837 : Compiler binds base class incorrectly (shortcoming of base circularity spec)
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6u23
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-02-08
  • Updated: 2024-04-12
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.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
1.6.0_18

ADDITIONAL OS VERSION INFORMATION :
Windows 7 Enterprise 64-bit

A DESCRIPTION OF THE PROBLEM :
Javac (any version) compiles the attached code without error, but when Main is run it prints "X.Q" instead of "A<T>.X.Q" as required by the language specification.  I think this is really a shortcoming of the specification for circular class declarations, but demonstrating my point is easier if I just start by reporting it as a compiler bug.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run attached program

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A<T>.X.Q

-or-

Compilation error complaining about base class circularity.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class A<T> {
  static class X {
    static class Q {
      public static void main() {
        System.out.println("A<T>.X.Q");
      }
    }
  }
}

class B extends A<B.Y.Q> {
  static class Y extends X { } // X here is inherited from A
}

class X {
  static class Q {
    public static void main() {
      System.out.println("X.Q");
    }
  }
}

class Main {
  public static void main(String[] args) {
    B.Y.Q.main();
  }
}

---------- END SOURCE ----------

Comments
Dan, can you please take a look - the compiler is wrong, but the problem stems (I think) from an underspecified circularity class check.
12-07-2013

Can you take a look at this bug? Feel free to defer it to 9. Thanks
21-06-2013

EVALUATION The following reduced test case is even more explicit: class A<T> { static class X { static class Q { } } } class B extends A<B.Y.Q> { //compiler error here static class Y extends X { } // X here should be inherited from A } class X {} The problem is that B's supertype is somewhat circular: its type-argument (B.Y.Q) depends on a member type of B itself (and members of B are undetermined until supertypes are fully resolved). This means that when we see 'B.Y.Q' we don't see (yet) that X comes from A - so that Q is inherited in B.Y. As a result, X is resolved to the wrong class. Another interesting case arises when we exploit A's type-parameter in some useful way: class A<T> { class X<T> { class Q { } } } class B extends A<B.Y.Q> { class Y extends X<String> { } // B inherits X<B.Y.Q>... } class X<U> {} In the above case, even if the compiler was smart enough to detect that Y's supertype is indeed A.X, there should still be an error, since X<String> != X<B.Y.Q>.
08-02-2011