Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 527731

Summary: Incorrect cycle detected in type hierarchy
Product: [Eclipse Project] JDT Reporter: Tobias Riemenschneider <tobys>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: manoj.palat, pouiller.gitblit, register.eclipse, stephan.herrmann, wHack23
Version: 4.7.1a   
Target Milestone: 4.7.3   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/110811
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=a2ee843b668ecf9aca7c99300671ad9c2845690b
https://git.eclipse.org/r/116554
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=b1c2a63442229d51e669de6df7b1c9d0e7e3af64
Whiteboard: regression
Attachments:
Description Flags
Example code triggering the defect. none

Description Tobias Riemenschneider CLA 2017-11-24 10:41:19 EST
Created attachment 271633 [details]
Example code triggering the defect.

When switching from Eclipse Neon to Eclipse Oxygen JDT starts complaining about a detected cycle in the type hierarchy. Eclipse Neon as well as Oracle JDK 1.7, 1.8 and 9) are fine with the classes (with respect to compilation and execution).

The defect occurs when we have a typed class OuterClass with a static inner interface InnerInterface and a typed static inner class InnerTypedClass implementing InnerInterface and OuterClass extends another class that is typed with InnerTypedClass (see attachment).
Comment 1 Stephan Herrmann CLA 2017-11-24 17:03:02 EST
ecj 4.7.1 still accepts the program.

Starting from 4.7.1a we get:

----------
1. ERROR in /tmp/OuterClass.java (at line 3)
        public class OuterClass<T> extends ArrayList<OuterClass.InnerTypedClass<T>> {
                     ^^^^^^^^^^
The hierarchy of the type OuterClass is inconsistent
----------
2. WARNING in /tmp/OuterClass.java (at line 3)
        public class OuterClass<T> extends ArrayList<OuterClass.InnerTypedClass<T>> {
                     ^^^^^^^^^^
The serializable class OuterClass does not declare a static final serialVersionUID field of type long
----------
3. ERROR in /tmp/OuterClass.java (at line 7)
        public static class InnerTypedClass<T> implements InnerInterface {}
                                                          ^^^^^^^^^^^^^^
Cycle detected: a cycle exists in the type hierarchy between OuterClass.InnerTypedClass<T> and OuterClass<T>
----------
3 problems (2 errors, 1 warning)


Should search the commit that caused this to change, but unfortunately there's a huge number of commits between .1 and .1a
Comment 2 Stephan Herrmann CLA 2017-11-24 17:27:52 EST
I bisected this to commit 68640a1ceae6bddcdd1ba7a60e1aa3feddb7585a on behalf of:

Bug 520874: [compiler] difference in behavior in single static import
and on-demand
	Fix to report nested types being part of a inheritance cycle.

Maybe the change was intended after all?

@Jay?
Comment 3 Stephan Herrmann CLA 2017-11-25 07:49:13 EST
The problem goes away with the pending fix in bug 526681 :)

*** This bug has been marked as a duplicate of bug 526681 ***
Comment 4 Stephan Herrmann CLA 2017-11-25 15:20:37 EST
After bug 526681 was proven invalid by reasoning according to JLS ยง8.1.4, this bug remains to be investigated.

According to 8.1.4 we have

InnerTypedClass<T> implements OuterClass.InnerInterface
=> InnerTypedClass depends on OuterClass, InnerInterface

OuterClass<T> extends ArrayList<OuterClass.InnerTypedClass<T>>
=> OuterClass depends on ArrayList

I see nothing in JLS that would let a type argument participate in cycle detection, but it seems that is what ecj is doing.
Comment 5 Stephan Herrmann CLA 2017-11-25 15:37:35 EST
(In reply to Stephan Herrmann from comment #4)
> I see nothing in JLS that would let a type argument participate in cycle
> detection, but it seems that is what ecj is doing.

TypeReference.resolveTypeArgument() was already trying to prevent this (PauseHierarchyCheck) but in nested invocations we were resetting the flag too soon. => Only reset what we actually set in the first place.


I re-purposed the existing gerrit for this bug and made the test from bug 52668 a negative test:

https://git.eclipse.org/r/#/c/110811/
Comment 6 Till Brychcy CLA 2017-11-25 16:44:28 EST
Bug 495953 also has an example of a bogus cycle reported when type variables are reported.
Comment 7 Till Brychcy CLA 2017-11-25 16:45:52 EST
(In reply to Till Brychcy from comment #6)
> Bug 495953 also has an example of a bogus cycle reported when type variables
> are reported.

I meant "where type variables are involved."
Comment 9 Stephan Herrmann CLA 2017-11-25 17:42:56 EST
(In reply to Eclipse Genie from comment #8)
> Gerrit change https://git.eclipse.org/r/110811 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=a2ee843b668ecf9aca7c99300671ad9c2845690b

Released to master for 4.8 M4

Bug stays open for back port.
Comment 10 Eclipse Genie CLA 2018-02-01 13:54:24 EST
New Gerrit change created: https://git.eclipse.org/r/116554
Comment 11 Stephan Herrmann CLA 2018-02-01 15:21:30 EST
(In reply to Eclipse Genie from comment #10)
> New Gerrit change created: https://git.eclipse.org/r/116554

Tests fail due to bug 530634
Comment 12 Eclipse Genie CLA 2018-02-03 16:21:41 EST
Gerrit change https://git.eclipse.org/r/116554 was merged to [R4_7_maintenance].
Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=b1c2a63442229d51e669de6df7b1c9d0e7e3af64
Comment 13 Stephan Herrmann CLA 2018-02-03 16:22:18 EST
(In reply to Eclipse Genie from comment #12)
> Gerrit change https://git.eclipse.org/r/116554 was merged to
> [R4_7_maintenance].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=b1c2a63442229d51e669de6df7b1c9d0e7e3af64

Released for 4.7.3
Comment 14 Manoj N Palat CLA 2018-02-13 01:41:08 EST
Verified for Eclipse Oxygen.3 (4.7.3) with Build id: M20180207-1700
Comment 15 Stephan Herrmann CLA 2018-02-15 08:26:01 EST
*** Bug 454053 has been marked as a duplicate of this bug. ***