JDK-4326631 : Spurious Cyclic Inheritance Error
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-03-31
  • Updated: 2023-11-17
  • Resolved: 2000-04-03
Related Reports
Duplicate :  
Relates :  
Description

Name: rlT66838			Date: 03/30/2000


java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.orc1-S, mixed mode)

The following source code compiles under jdk 1.1.8, 1.2.2, and 1.3beta but not
under jdk1.3rc1:

//----------

public class Test
  implements Test.Inner
{
  public static interface Inner
  {
  }
}

//----------

The following compiler error is reported:

Test.java:4: cyclic inheritance involving Test
  public static interface Inner
                ^
1 error

//----------

The source code is legal Java. The error is spurious.

I submitted this bug report yesterday but made an error in the source code which
prevented compilation using any version. This is a corrected submission.
(Review ID: 103094) 
======================================================================

Comments
One reason circularity is difficult is that names in the 'extends'/'implements' clause may need to be resolved through inheritance. class A implements A.B, A.C { interface C { interface B {} } } If a class has a circular 'extends', then resolving the superclass and computing the inherited members of the class will depend on each other. (In theory, it might be possible to tease apart this circularity, but it's a difficult problem.) See also JDK-6863465 for some tricky cases involving circularity detection.
17-11-2023

EVALUATION This example is *not* legal, and this is made clear in the forthcoming 2nd edition of the Java Language Specification. Classes simultaneously related by both inheritance and enclosure are problematical, however the original innerclasses whitepaper did not adequately address the issue, nor did the pre-1.3 compilers implement a consistent policy. In JLS 2nd edition, the rule against cyclic inheritance has been extended to prohibit a class or interface from "depending" on itself, directly or indirectly. A type depends not only on types that it extends or implements, but also on types that serve as qualifiers within the names of those types. william.maddox@Eng 2000-04-03
03-04-2000