Details
-
Type:
Bug
-
Status: Closed
-
Priority:
P4
-
Resolution: Fixed
-
Affects Version/s: 8
-
Fix Version/s: 8u40
-
Component/s: specification
-
Labels:
-
Subcomponent:
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).
-------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).
Attachments
Issue Links
- relates to
-
JDK-8158008 8.1.4: Clarify "the fully qualified form"
-
- Open
-
-
JDK-6863462 Unclear specification: circular class hierarchy dependency via static imports
-
- Open
-
-
JDK-8056066 JEP 216: Process Import Statements Correctly
-
- Closed
-