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

Inconsistent removeIf behavior between collection views of IMap #12198

Closed
nlwillia opened this issue Jan 25, 2018 · 0 comments · Fixed by #15013
Closed

Inconsistent removeIf behavior between collection views of IMap #12198

nlwillia opened this issue Jan 25, 2018 · 0 comments · Fixed by #15013

Comments

@nlwillia
Copy link

@nlwillia nlwillia commented Jan 25, 2018

java.util.Collection has a default removeIf method that iterates and removes elements based on a Predicate.

IMap#values().removeIf(...) fails immediately with UnsupportedOperationException if called.

IMap#keySet().removeIf(...) and IMap#entrySet().removeIf(...) do not throw an exception, but don't have any effect on the map either. (Tested in 3.9.2)

The limited support for collection clone views is mentioned in the javadoc for IMap, but this is a significant pitfall in actual usage where you're more likely to follow the completion suggestions of your IDE. If Hazelcast is not going to support these methods, it should at least override them to fail consistently.

edit: This is mostly with the Java client, but note that member only errors on remove if an item is found.

connection method c=m.entrySet() c=m.keySet() c=m.values()
member c.remove(null) no error no error no error
member c.remove(c.iterator().next()) UnsupportedOperationException UnsupportedOperationException UnsupportedOperationException
member c.removeIf(x->true) UnsupportedOperationException UnsupportedOperationException UnsupportedOperationException
member c.removeAll(c) UnsupportedOperationException UnsupportedOperationException UnsupportedOperationException
member c.retainAll(Collections.emptyList()) UnsupportedOperationException UnsupportedOperationException UnsupportedOperationException
member c.clear() UnsupportedOperationException UnsupportedOperationException UnsupportedOperationException
member iter.next(); iter.remove() UnsupportedOperationException UnsupportedOperationException UnsupportedOperationException
client c.remove(null) no error no error UnsupportedOperationException
client c.remove(c.iterator().next()) no error no error UnsupportedOperationException
client c.removeIf(x->true) no error no error UnsupportedOperationException
client c.removeAll(c) no error no error UnsupportedOperationException
client c.retainAll(Collections.emptyList()) no error no error UnsupportedOperationException
client c.clear() no error no error UnsupportedOperationException
client iter.next(); iter.remove() no error no error UnsupportedOperationException
@mmedenjak mmedenjak modified the milestones: 3.11, 3.12 Aug 27, 2018
@dbrimley dbrimley removed this from the 3.12 milestone Nov 8, 2018
@mmedenjak mmedenjak added this to the 4.0 milestone Apr 17, 2019
petrpleshachkov added a commit to petrpleshachkov/hazelcast that referenced this issue May 10, 2019
Consistently throw UnsupportedOperationException on attempt to update a
collection returned by keySet, entrySet, localKeySet, values and getAll
methods.

The fix may change the behavior of existing customers throwing an
exception instead of ignoring the updates.

Moved InflatableSet to internal package making it for internal use only.

Fixes: hazelcast#12198
petrpleshachkov added a commit to petrpleshachkov/hazelcast that referenced this issue May 14, 2019
Minor changes to take into account reviewer's comments.
petrpleshachkov added a commit to petrpleshachkov/hazelcast that referenced this issue May 14, 2019
Take into account comments of reviewer.
petrpleshachkov added a commit to petrpleshachkov/hazelcast that referenced this issue May 14, 2019
Minor changes to remove unreachable code and adjust names of some classes.
petrpleshachkov added a commit that referenced this issue May 15, 2019
* Make collection clones of IMap immutable (#12198)

Consistently throw UnsupportedOperationException on attempt to update a
collection returned by keySet, entrySet, localKeySet, values and getAll
methods.

The fix may change the behavior of existing customers throwing an
exception instead of ignoring the updates.

Moved InflatableSet to internal package making it for internal use only.

Fixes: #12198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.