From e7079ca36aef1b74696f50fbdfe11d99273274d7 Mon Sep 17 00:00:00 2001 From: Rui Gonçalves Date: Wed, 21 Oct 2015 21:22:18 +0100 Subject: SI-9497 Fix SetLike#clear() default implementation When dealing with mutable collections, it is not safe to assume iterators will remain consistent when the collection is modified mid-traversal. The bug reported in SI-9497 is very similar to SI-7269, "ConcurrentModificationException when filtering converted Java HashMap". Then, only the `retain` method was fixed. This commit fixes `clear`, which had the same problem. --- src/library/scala/collection/mutable/SetLike.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/library') diff --git a/src/library/scala/collection/mutable/SetLike.scala b/src/library/scala/collection/mutable/SetLike.scala index 81a71adc91..01075a2633 100644 --- a/src/library/scala/collection/mutable/SetLike.scala +++ b/src/library/scala/collection/mutable/SetLike.scala @@ -129,7 +129,9 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]] /** Removes all elements from the set. After this operation is completed, * the set will be empty. */ - def clear() { foreach(-=) } + def clear(): Unit = + for (elem <- this.toList) + this -= elem override def clone(): This = empty ++= repr.seq -- cgit v1.2.3