Bug 166995 - [DataBinding] Need to always check result of collection.remove()
Summary: [DataBinding] Need to always check result of collection.remove()
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-06 15:17 EST by Dave Orme CLA
Modified: 2019-09-06 16:06 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Orme CLA 2006-12-06 15:17:41 EST
Anywhere we use a collection and call collection.remove(), we need to check that the expected object was found and removed by the collection.  In this situation, we should throw an exception.

The #1 cause of hard to find data binding bugs has been an incorrect equals() or hashCode() implementation.  We have spent literally days on a couple of bugs tracing through our code and through data binding when our overall algorithm was perfect and there was no bug in data binding.  In both of these cases the bug turned out to be some quirk or something just wrong about our equals() or hashCode() implementation in a domain object.

If an exception was always thrown when data binding tried to remove an object and couldn't (perhaps with a message "check your equals() and hashCode() methods"), we would have failed fast rather than have a hard-to-find bug.
Comment 1 Brad Reynolds CLA 2006-12-06 16:29:18 EST
-1

We'd be changing the contract of List by doing this.  There are use cases where the consumer doesn't care if the item was found and changing this changes assumptions that are already in place and limits the ability of hiding the implementation.

I don't necessarily have a recommendation for how to resolve this yet but I don't think changing remove() is the way to go.
Comment 2 Boris Bokowski CLA 2006-12-06 16:45:36 EST
Dave, could you point us to places in the current code (or one example) where we call remove and should check for the returned object?

I looked at ListBinding and it works based on indices, not elements, so it seems that you are talking about the not-yet-existing SetBinding?
Comment 3 Brad Reynolds CLA 2006-12-07 00:56:40 EST
Ah, so I think I misunderstood your intentions.  If you're saying in bindings we need to check this that's a different story altogether. :)
Comment 4 Dave Orme CLA 2006-12-07 10:07:15 EST
I'm not sure of the current code's status, but in the ListBinding implementation we have here at TPC, there are still some places where we just call list.remove() when applying the ListDiff.

The intent of filing the bug was mostly as a "note to self", make sure we get this right in the future or we'll have people asking on the newsgroup why data binding isn't working when the problem is really their equals/hashCode implementations.
Comment 5 Eclipse Webmaster CLA 2019-09-06 16:06:45 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.