JDK-7152962 : Compiler misreporting cyclic inheritance
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-03-12
  • Updated: 2017-10-17
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
tbd_minorUnresolved
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
1.7.0

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows Version 6.1.7601

A DESCRIPTION OF THE PROBLEM :
I have the following two files

G.java
------------------------
package foo.bar;

import foo.bar.H.HH;
import foo.bar.H.HH.HHH;

class G extends HH{
	
	static class GG extends HHH {}
	
}
------------------------

H.java
------------------------
package foo.bar;

import foo.bar.G.GG;

class H extends G{
	
	
	static class HH extends GG{
		
		static class HHH{}
		
	}
}
------------------------

Clearly, there is no hierarchy circle, the hierarchy is H -> G -> H.HH -> G.GG -> H.HH.HHH. I checked the language specification and could not find out why this code should be erroneous. It is neither a hierarchy circle, nor a depends circle, because no class is explicitly used as qualifier in the extends clause.

when trying to compile these classes, I get the following error

H.java:8: error: cannot find symbol
        static class HH extends GG{
                                ^
  symbol:   class GG
  location: class H
H.java:5: error: cyclic inheritance involving H
class H extends G{
^
2 errors

The first error is strange but could be a result of the second. GG is in scope, since HH is in H which extends G and thus brings GG into scope. The second error is strange as well, as there is no cycle.

Note that the Ecplise JDT java compiler does not raise any errors here.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.) Write the following java files

G.java
------------------------
package foo.bar;

import foo.bar.H.HH;
import foo.bar.H.HH.HHH;

class G extends HH{
	
	static class GG extends HHH {}
	
}
------------------------

H.java
------------------------
package foo.bar;

import foo.bar.G.GG;

class H extends G{
	
	
	static class HH extends GG{
		
		static class HHH{}
		
	}
}
------------------------

2. run javac H.java G.java in the appropriate directory

3. Receive the error output

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No compile errors
ACTUAL -
Following compile errors:

H.java:8: error: cannot find symbol
        static class HH extends GG{
                                ^
  symbol:   class GG
  location: class H
H.java:5: error: cyclic inheritance involving H
class H extends G{
^
2 errors

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
not necessary, this is a constructed case. Its only use is to detect a discrepancy between the specification and the compiler. In my opinion, it would be even better to forbid one class extending a member class of its subclasses.