Bug 319885

Summary: Spurious 'cycle detected'/'hierarchy inconsistent' errors if a type that WOULD be cyclic is static-imported
Product: [Eclipse Project] JDT Reporter: Ben Davis <entheh>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, entheh, Olivier_Thomann, stephan.herrmann
Version: 3.6   
Target Milestone: 3.7 M1   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Patch under consideration.
none
Patch under test none

Description Ben Davis CLA 2010-07-14 13:12:06 EDT
Build Identifier: M20090211-1700

While resolving an (explicit) 'extends' or 'implements' clause (e.g. extends Object), Eclipse scans all the type names (e.g. BlackCat) made available via static import. If it finds a name that WOULD create a cycle, then it will sometimes report 'cycle detected' even though there isn't one. Whether these spurious errors appear seems to depend on compilation order.

At least, that's my conclusion from the 'steps to reproduce'. What's actually going on may be more complicated, or different entirely.

Reproducible: Sometimes

Steps to Reproduce:
1. Create a project with the following two files. It should compile.
2. Uncomment the static import. The errors should appear.
   - If you don't see the errors, try 'Project -> Clean'.
3. Remove the words "extends Object". The errors disappear.

eclipsecyclebug/BrownBox.java:

package eclipsecyclebug;
import static eclipsecyclebug.GreenBox.*;
public interface BrownBox {
    public static class BlackCat extends Cat {}
}

eclipsecyclebug/GreenBox.java:

package eclipsecyclebug;
//import static eclipsecyclebug.BrownBox.*;
public interface GreenBox {
    public static class Cat extends Object {}
}

The errors:

BrownBox.java: "Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and GreenBox.Cat"
GreenBox.java: "The hierarchy of type Cat is inconsistent"
Comment 1 Ben Davis CLA 2010-07-14 13:30:44 EDT
A thought: Eclipse seems to compile in reverse alphabetical order for me. It's probably trying to resolve GreenBox.Cat first. In order to resolve the 'extends' clause, it has to resolve the static imports. While doing that, it finds BrownBox.BlackCat, and sees that it extends GreenBox.Cat - a type it is already trying to resolve. Hence it generates a 'cycle' error.

Hope that helps!
Comment 2 Ayushman Jain CLA 2010-07-15 03:36:14 EDT
Reproduced with 3.6. I'll investigate.
Comment 3 Srikanth Sankaran CLA 2010-07-19 05:14:33 EDT
Created attachment 174598 [details]
Patch under consideration.

I discussed this with Ayush and we agreed that I'll fix
this and he will review the patch.
Comment 4 Srikanth Sankaran CLA 2010-07-19 08:22:38 EDT
Comment on attachment 174598 [details]
Patch under consideration.

This patch is the result of muddled thinking. Will need rework.
Comment 5 Srikanth Sankaran CLA 2010-07-20 02:41:46 EDT
Created attachment 174702 [details]
Patch under test
Comment 6 Srikanth Sankaran CLA 2010-07-20 04:23:48 EDT
All tests pass, Ayush, please review, TIA.
Comment 7 Ayushman Jain CLA 2010-07-26 09:38:22 EDT
(In reply to comment #6)
> All tests pass, Ayush, please review, TIA.

Looks good.
Comment 8 Srikanth Sankaran CLA 2010-07-26 10:48:18 EDT
Released in HEAD for 3.7 M1
Comment 9 Olivier Thomann CLA 2010-08-04 16:12:26 EDT
Verified for 3.7M1.