moremore0812 / cqengine

Automatically exported from code.google.com/p/cqengine
0 stars 0 forks source link

Set remove() and removeAll() doesn't follow substitutability principle. #27

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

Set.remove(o) takes on Object where as Set.add(E) takes generic, this is 
because Set.remove() can not damage internals of Set representation even if the 
type doesn't match the element. Because only if the element is present it gets 
removed.

However in IndexedCollection implementation we pass the object after (an 
unchecked cast), to the indices. Now the indices are called even the object is 
removed or not. This causes Class Cast Exception. Instead we should check first 
if the element is a member only then call index update steps.

More here: 
http://smallwig.blogspot.in/2007/12/why-does-setcontains-take-object-not-e.html

Original issue reported on code.google.com by anita.v...@inmobi.com on 9 Nov 2013 at 9:40

Attachments:

GoogleCodeExporter commented 9 years ago
This fix also gives a reasonable performance boost.

Original comment by anita.v...@inmobi.com on 9 Nov 2013 at 9:42

GoogleCodeExporter commented 9 years ago
Yes, this would be a worthwhile improvement. I'll apply your patch at the 
weekend, for inclusion in the next release. I'll make a maintenance release 
including the few recent enhancements soon. Thanks!

Original comment by ni...@npgall.com on 13 Nov 2013 at 11:37

GoogleCodeExporter commented 9 years ago
Patch applied in trunk. Many thanks Atul.

Original comment by ni...@npgall.com on 22 Nov 2013 at 9:24

GoogleCodeExporter commented 9 years ago
Fixed in release 1.2.4. Many thanks!

Original comment by ni...@npgall.com on 22 Nov 2013 at 10:02