Bug 90486 - Give more info when a dependency cycle is detected
Summary: Give more info when a dependency cycle is detected
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.7 RC1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 291274 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-06 12:46 EDT by Roberto Scaramuzzi CLA
Modified: 2017-11-13 12:59 EST (History)
7 users (show)

See Also:
Olivier_Thomann: review+


Attachments
patch under test (3.94 KB, patch)
2011-04-25 05:16 EDT, Ayushman Jain CLA
no flags Details | Diff
proposed fix v1.0 + regression tests (23.15 KB, patch)
2011-04-25 10:01 EDT, Ayushman Jain CLA
no flags Details | Diff
proposed fix v1.1 + regression tests (25.54 KB, patch)
2011-04-25 15:01 EDT, Ayushman Jain CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roberto Scaramuzzi CLA 2005-04-06 12:46:55 EDT
I introduced a dependency cycle between some of my Java projects. I have about
100 projects in my workspace and now I have 58 warnings that a dependency cycle
has been detected for project ... (substitute a different project for each
warning). No additional information is given. This makes it a lot more work to
figure out what the cycle is. The UI should report what the cycle is (for
example by adding (ProjectA->ProjectB->ProjectC->ProjectA) to the text of the
warning; I do understand that this is potentially a very long string).
Comment 1 Philipe Mulet CLA 2005-04-07 08:01:50 EDT
Deferring post 3.1
Comment 2 Eclipse Webmaster CLA 2009-08-30 02:40:22 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.
Comment 3 Dani Megert CLA 2010-04-20 06:26:28 EDT
Just ran into that as well: when we report a cycle on a project we should at least differentiate whether the project is part of the cycle or whether it only references a cycle:

A -> B -> C -> B ==> 
The build path of project 'A' references projects that build a cycle

A -> B -> C -> A ==> 
A cycle was detected in the build path of project 'A'

The PDE editor can then be used to detect the cycle.
Comment 4 Dani Megert CLA 2010-04-20 07:26:26 EDT
*** Bug 291274 has been marked as a duplicate of this bug. ***
Comment 5 Olivier Thomann CLA 2011-04-21 09:20:10 EDT
The best we can do with the cycle detection is to display the list of projects involved in the cycle.
Since a set is used to store project's paths in the cycle, the project's names would be displayed in a random order.
Would this be sufficient ?
Comment 6 Dani Megert CLA 2011-04-21 09:38:32 EDT
(In reply to comment #5)
> The best we can do with the cycle detection is to display the list of projects
> involved in the cycle.
> Since a set is used to store project's paths in the cycle, the project's names
> would be displayed in a random order.
> Would this be sufficient ?

How hard is it to replace the set with a list?
Comment 7 Olivier Thomann CLA 2011-04-21 09:41:29 EDT
It is not hard. It is just less efficient.
Comment 8 Dani Megert CLA 2011-04-21 09:50:27 EDT
(In reply to comment #7)
> It is not hard. It is just less efficient.

k. We could build the graph after the fact i.e. in the rare case we detect a cycle we build the full graph. That way only users with cycles pay.
Comment 9 Olivier Thomann CLA 2011-04-21 13:05:40 EDT
Ayushman, please investigate.
The only thing we should do at this time is to create a string representation of the cycle that we can put as part of the message for the problem reported for classpath cycle.
Comment 10 Olivier Thomann CLA 2011-04-21 14:04:49 EDT
Would be good for RC1
Comment 11 Olivier Thomann CLA 2011-04-21 14:05:11 EDT
If ready in time for M7, this should go in M7.
Comment 12 Ayushman Jain CLA 2011-04-25 05:16:35 EDT
Created attachment 193981 [details]
patch under test

This changes the error message from 
"A cycle was detected in the build path of project P"
to
"A cycle was detected in the build path of project P. The cycle consists of projects {P, P1, P2}"

Running tests to check what all tests need to be updated.
Comment 13 Ayushman Jain CLA 2011-04-25 10:01:47 EDT
Created attachment 193987 [details]
proposed fix v1.0 + regression tests

The above fix with the tests updated to reflect the new error message.
Comment 14 Ayushman Jain CLA 2011-04-25 15:01:57 EDT
Created attachment 194014 [details]
proposed fix v1.1 + regression tests

Same fix but using a LinkedHashMap instead of a HashMap to store the cycleParticipants. This is because HashMap does not always maintain the insertion order and so the tests were failing or passing at random on subsequent runs (The error string would sometime say P1, P2, P3 and the other times would say P3, P1, P2). Fixed the problem with this patch.
Comment 15 Olivier Thomann CLA 2011-05-03 11:58:05 EDT
Ok, listing the project involved in the cycle is good enough for 3.7.
However I would not change the actual way to compute the cycle.

I would add a method on JavaProject called getCycle() that returns a string representation of the cycle.
Comment 16 Ayushman Jain CLA 2011-05-03 15:31:29 EDT
(In reply to comment #15)
> However I would not change the actual way to compute the cycle.
Are you referring to using LinkedHashSet in place of HashSet? I didn't change the way to compute the cycle at all. Just changed the way to store it in a consistent way everytime.

> I would add a method on JavaProject called getCycle() that returns a string
> representation of the cycle.
How will that method find out the projects that constitute the cycle? From the 
cycleParticipants hashSet, no? Or does it recalculate all the cycle elements? If the former is the answer, then again we might end up printing, say {P3, P2, P1} or {P1, P2, P3} on random occasions. If the latter is the answer, I don't understand why to repeat the work already done.

Let me know what you think.
Comment 17 Olivier Thomann CLA 2011-05-03 16:15:07 EDT
Agree. For now we can use a LinkedHashSet to guarantee the iteration order.
+1 for your patch.
Comment 18 Ayushman Jain CLA 2011-05-04 10:48:20 EDT
Released in HEAD for 3.7RC1.
Comment 19 Dani Megert CLA 2011-05-06 02:11:42 EDT
Verified in I20110505-0800.