JDK-6982173: Small problem causing thousands of wasted CPU hours
Alan Snyder
javalists at cbfiddle.com
Thu Feb 14 17:30:35 UTC 2019
Right, I see that now.
Care must be exercised if this method is used on collections that
do not comply with the general contract for {@code Collection}.
So, what does this mean? Are we catering to incorrect implementations?
> On Feb 13, 2019, at 9:07 PM, Stuart Marks <stuart.marks at oracle.com> wrote:
>
> On 2/13/19 7:22 PM, Alan Snyder wrote:
>> If we take this route, how about changing the parameter type to Iterable?
>
> Won't work. Where I've ended up is that we need to iterate over "this" collection and, for each element, call contains() on the parameter. The AbstractCollection.removeAll() implementation does something like this:
>
> removeAll(Collection<?> c) {
> for (Iterator<?> it = iterator(); it.hasNext();) {
> if (c.contains(it.next())) {
> it.remove();
> }
> }
> }
>
> Since we call contains() on the parameter, it has to be a Collection.
>
> s'marks
>
More information about the core-libs-dev
mailing list