JDK-8041994 : 8.1.4: Superclass/superinterface "depends" relationship misses imported qualified names
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-04-28
  • Updated: 2017-02-17
  • Resolved: 2015-02-16
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 8
8u40Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Example below cannot compile due to error "cyclic inheritance involving test.A".

-------Example----------
//file A.java
package test;

class A extends C {
    static class B {}
}

//file C.java
package test;

import static test.A.B;

class C extends B  {}
------------------------------

Same error for static-import-on-demand clause and for various combinations of classes and interfaces.
This behaviour is expected - C depends on A because B is nested in A. But specification says nothing about dependencies via static import.

This is what specification says about dependencies:

Section 8.1.4 (http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.1.4):
"A class C directly depends on a type T if T is mentioned in the extends or implements clause of C either as a superclass or superinterface, or as a qualifier of a superclass or superinterface name.

A class C depends on a reference type T if any of the following is true:
 C directly depends on T.
 C directly depends on an interface I that depends (��9.1.3) on T.
 C directly depends on a class D that depends on T (using this definition recursively)."

Section 9.1.3 (http://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.1.3):
"An interface I directly depends on a type T if T is mentioned in the extends clause of I either as a superinterface or as a qualifier within a superinterface name.

An interface I depends on a reference type T if any of the following is true:
 I directly depends on T.
 I directly depends on a class C that depends on T (��8.1.5).
 I directly depends on an interface J that depends on T (using this definition recursively).

It is a compile-time error if an interface depends on itself."

Possible solution would be to add cases with static import in "directly depends..." parts (similarly to qualifier cases).
Comments
The Description speaks of static imports, but the issue applies to normal imports too. The problem is with the phrase: "a qualifier of a superclass or superinterface name." because it doesn't seem to prohibit a simple name that is in scope due to an import, but for which the fully qualified name would be illegal if written directly. What the phrase really means to say is: "a qualifier in the fully qualified form of a superclass or superinterface name." (+ similarly for 9.1.3) Stepping back, the directly-depends relationship for classes and interfaces was introduced in JLS2 to clarify JLS1 and to cover superclasses/superinterfaces that are nested classes (e.g. A.B in the Description). It's a very minor sin that the relationship didn't clearly cover qualified names that were written in simple form due to imports.
28-04-2014