Bug 485775

Summary: [compiler] Doesn't report cycle inheritance problem which is detected by Oracle JDK
Product: [Eclipse Project] JDT Reporter: leokom leokom <lrozenblyum>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jmhenaff, manoj.palat, stephan.herrmann, sxenos
Version: 4.5.1Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug
Attachments:
Description Flags
File with no cycle detected by ecj none

Description leokom leokom CLA 2016-01-13 11:19:53 EST
Let's have 2 classes:

public class First implements Second.SecondInterf {
    interface FirstInterf {

    }
}

public class Second implements First.FirstInterf {
    interface SecondInterf {

    }
}

javac First.java reports error: cyclic inheritance involving Second

While Eclipse compiler silently allows such cycle.
Probably Eclipse compiler should have validation for such situation synchronous with the JDK (because otherwise code that compiles well in Eclipse fails to compile under standalone JDK).

Related discussion on stackoverflow about why Java prohibits such cycle:
http://stackoverflow.com/a/7998053/1429367
Spec:
https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.1.4
Comment 1 Jean-Marie HENAFF CLA 2016-08-04 12:17:34 EDT
Created attachment 263457 [details]
File with no cycle detected by ecj
Comment 2 Jean-Marie HENAFF CLA 2016-08-04 12:20:35 EDT
Reproduced on Linux with latest integration and nightly build (N20160730).

I've attached source files to reproduce the case.

Note that removing the imports make the compilation fail.
Comment 3 Stephan Herrmann CLA 2016-08-04 12:58:44 EDT
Well, the example in comment 0 is rejected by all versions of ecj.
This is in line with javac's behavior and the accepted answer on SO.

The attached project, OTOH, uses imports and simple type references, and hence I don't see X mentioned in its hierarchy. => This program does not violate JLS as quoted in the SO answer.

However, the corresponding JLS section has since been changed from

  as a qualifier of a superclass or superinterface name

to

  as a qualifier in the fully qualified form of a superclass or superinterface name

This change was effective as of Java 7 and should be adopted by ecj.
Comment 4 Stephan Herrmann CLA 2016-08-04 13:01:26 EDT
Also javac 6 accepts the attached example, demonstrating that this was an intented change.
Comment 5 Manoj N Palat CLA 2018-05-17 03:24:39 EDT
bulk move out of 4.8
Comment 6 Manoj N Palat CLA 2018-08-16 00:09:30 EDT
Bulk move out of 4.9
Comment 7 Eclipse Genie CLA 2022-06-06 13:00:32 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 8 Eclipse Genie CLA 2024-05-27 17:49:15 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 9 leokom leokom CLA 2024-05-28 02:53:52 EDT
Works fine now: in Eclipse 2022-12 and 2024-03 with JDK17 we have such compilation errors in Eclipse, which correlates with Oracle javac.

The hierarchy of the type First is inconsistent
The hierarchy of the type Second is inconsistent
Cycle detected: a cycle exists in the type hierarchy between Second and First