Bug 319885 - Spurious 'cycle detected'/'hierarchy inconsistent' errors if a type that WOULD be cyclic is static-imported
Summary: Spurious 'cycle detected'/'hierarchy inconsistent' errors if a type that WOUL...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.7 M1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-14 13:12 EDT by Ben Davis CLA
Modified: 2010-08-04 16:12 EDT (History)
4 users (show)

See Also:


Attachments
Patch under consideration. (9.81 KB, patch)
2010-07-19 05:14 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Patch under test (15.30 KB, patch)
2010-07-20 02:41 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.