Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Jun 15, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link


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
Copy link
Author

This fix also gives a reasonable performance boost.

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

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Patch applied in trunk. Many thanks Atul.

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

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Fixed in release 1.2.4. Many thanks!

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

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant