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

Bug 362227

Summary: MultiRule#equals is missing
Product: [Eclipse Project] Platform Reporter: Szymon Ptaszkiewicz <sptaszkiewicz>
Component: RuntimeAssignee: platform-runtime-inbox <platform-runtime-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: john.arthorne, remy.suen
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch v1 none

Description Szymon Ptaszkiewicz CLA 2011-10-27 14:10:17 EDT
Current implementation of MultiRule violates ISchedulingRule contract because of missing #equals method. Consider the following example:

MultiRule multi1 = new MultiRule(new ISchedulingRule[] {child1, child2});
MultiRule multi2 = new MultiRule(new ISchedulingRule[] {child2, child1});
multi1.contains(multi2)); => true
multi2.contains(multi1)); => true
multi1.equals(multi2));   => false but should be true

Without proper implementation of MultiRule#equals we are not able to satisfy the requirement for antisymmetric MultiRule#contains. Missing #equals is also dangerous in cases where #equals is used implicitly (lists, sets, etc.). See for example DeadlockDetector#locks and DeadlockDetector#indexOf(ISchedulingRule, boolean).
Comment 1 Szymon Ptaszkiewicz CLA 2011-10-27 14:34:38 EDT
I will try to prepare a patch for that.
Comment 2 John Arthorne CLA 2011-10-27 15:07:51 EDT
Hmm, I think it is dangerous to rely on the implementation of equals for an ISchedulingRule. Since the client can implement this interface, we can't assume that the equals method on all objects implementing ISchedulingRule has any relationship to the contains method. For example Resource#contains only looks at the path, whereas Resource#equals looks at the path, workspace, and type. Maybe the javadoc on ISchedulingRule#contains should be reworded here.
Comment 3 Szymon Ptaszkiewicz CLA 2011-10-28 10:08:33 EDT
Exactly. And that means that whenever we need to check if two ISchedulingRules are equal, we should use a.contains(b) && b.contains(a) instead of a.equals(b). Since this change is going to be a bigger code change in core.jobs, I will open another bug for that and in this bug we just handle problems with MultiRule.

Regarding the Resource#contains method, I think we should add a check for workspace there. After that, when we eventually implement multi-workspace support, two resources with the same path but in different workspace would not be in conflict with each other. That of course requires a separate bug in Platform/Resources.
Comment 4 Szymon Ptaszkiewicz CLA 2011-11-01 08:50:34 EDT
Opened bug 362512 and bug 362515.
Comment 5 Szymon Ptaszkiewicz CLA 2012-04-23 10:35:17 EDT
(In reply to comment #2)
> Hmm, I think it is dangerous to rely on the implementation of equals for an
> ISchedulingRule. Since the client can implement this interface, we can't assume
> that the equals method on all objects implementing ISchedulingRule has any
> relationship to the contains method. For example Resource#contains only looks
> at the path, whereas Resource#equals looks at the path, workspace, and type.
> Maybe the javadoc on ISchedulingRule#contains should be reworded here.

For any two scheduling rules a and b, if a.equals(b), then a.contains(b) && b.contains(a). But, if a.contains(b) && b.contains(a), then it does not necessarily imply that a.equals(b) because a and b may be of different type.

So, I guess there are two separate definitions of equality:
1) Scheduling rules equality: two rules are equal iff a.contains(b) && b.contains(a).
2) Objects equality: two objects are equal iff a.equals(b).

We now get two implications:
A) 1) implies 2)
B) 2) implies 1)

B) is always correct for any two scheduling rules, but A) is true only for scheduling rules of the same type.

Because of that, I think that the javadoc of the contains method is wrong. Antisymmetric property should be valid for the whole set of all scheduling rules not only for the particular implementation (for one type). Especially, we should avoid the "equals" there. ISchedulingRule#contains deals with members of the relation whereas Object#equals deals with objects and I think we should not mix those two together.
Comment 6 Szymon Ptaszkiewicz CLA 2012-04-24 04:59:40 EDT
Created attachment 214447 [details]
Patch v1
Comment 7 John Arthorne CLA 2012-04-24 09:40:45 EDT
Your patch doesn't seem to match the analysis. I don't think we can assume anything about the equals method on implementations of ISchedulingRule. So we should really just avoid talking about equals rather than adding implementations of equuals to our rules.
Comment 8 Szymon Ptaszkiewicz CLA 2012-04-24 10:24:58 EDT
(In reply to comment #7)
> Your patch doesn't seem to match the analysis. I don't think we can assume
> anything about the equals method on implementations of ISchedulingRule. So we
> should really just avoid talking about equals rather than adding
> implementations of equuals to our rules.

In that case, I think this bug is INVALID and we should get rid of all references to ISchedulingRule#equals (bug 362512).
Comment 9 Szymon Ptaszkiewicz CLA 2012-04-24 10:52:01 EDT
Does it sound reasonable?
Comment 10 John Arthorne CLA 2012-04-24 11:28:37 EDT
Yes, thanks Szymon.