-
Notifications
You must be signed in to change notification settings - Fork 11k
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
UnmodifiableMultiset.removeIf() should throw UnsupportedOperationException
#6702
Comments
Even if there's nothing to remove, removeIf() should throw an `UnsupportedOperationException`. see google#6702
IMO it's somewhat similar to #3909. |
Thanks for the very quick response. You're right, it is the same idea as #3909. As @kevinb9n said in that one:
That was my thought for this one as well. |
Here's a simple PR to fix it, if desired: #6703 |
The downside, of course, is that this may break code that was implicitly relying on the current behaviour. Even if it might have been better to throw from the outset, it's less clear that changing it now is worth the small risk of breakage. |
Makes sense. For context, this came up as part of adding an AssertJ also keeps a list of known immutable collection types, to handle cases like this. If you decide to keep the current behavior, we can add |
I tried running all of Google's tests (from nearly all of Google's products and services) with an equivalent change in place, and there were no failures. There are actually only a few dozen uses of |
Sounds good. Thanks! |
Even if there's nothing to remove, `removeIf(Predicate)` should throw an `UnsupportedOperationException`. This is theoretically an incompatible change, in that some existing code might have been calling `removeIf` with a predicate that is never true. None of Google's internal uses show this problem in tests. Fixes #6702. Closes #6703. RELNOTES=`Multisets.unmodifiableMultiset(set).removeIf(predicate)` now throws an exception always, even if nothing matches `predicate`. PiperOrigin-RevId: 564194620
Even if there's nothing to remove, `removeIf(Predicate)` should throw an `UnsupportedOperationException`. This is theoretically an incompatible change, in that some existing code might have been calling `removeIf` with a predicate that is never true. None of Google's internal uses show this problem in tests. Fixes #6702. Closes #6703. RELNOTES=`Multisets.unmodifiableMultiset(set).removeIf(predicate)` now throws an exception always, even if nothing matches `predicate`. PiperOrigin-RevId: 564194620
UnmodifiableMultiset.removeIf()
should throwUnsupportedOperationException
, even if nothing would be removed. This would make it match the other mutating methods inUnmodifiableMultiset
.Currently, if the predicate doesn't accept any of the elements in the set,
removeIf
succeeds and does nothing. The set isn't modified, but it's surprising thatremoveIf
doesn't throwUnsupportedOperationException
in this case.I'll attach a PR which will fix this, assuming you agree it should be changed.
The text was updated successfully, but these errors were encountered: