diff options
author | Aleksandar Prokopec <axel22@gmail.com> | 2013-05-30 14:37:01 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-06-09 15:40:54 -0400 |
commit | c71fa58a35690672bc4626d18b5016b98bfcc5f8 (patch) | |
tree | c00283863cc4b713db2dcc1aa3e583341cd28780 | |
parent | e3c318649c4318412c8d7e3cbee4689489f6ccb1 (diff) | |
download | scala-c71fa58a35690672bc4626d18b5016b98bfcc5f8.tar.gz scala-c71fa58a35690672bc4626d18b5016b98bfcc5f8.tar.bz2 scala-c71fa58a35690672bc4626d18b5016b98bfcc5f8.zip |
[backport] SI-7498 ParTrieMap.foreach no longer crashes
Previously, the `split` method of the `ParTrieMap` iterator threw
an exception when splitting a splitter that iterated over nodes
whose hash codes collide.
This was due to reusing the iterator of the list of colliding keys
rather than creating a new splitter.
This commit changes the `subdivide` method to create a new
iterator using the factory method of the current trie map
iterator rather than returning a `LinearSeqLike` iterator.
-rw-r--r-- | src/library/scala/collection/concurrent/TrieMap.scala | 7 | ||||
-rw-r--r-- | test/files/run/t7498.scala | 20 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala index 6c11c5bcb5..714260fa8a 100644 --- a/src/library/scala/collection/concurrent/TrieMap.scala +++ b/src/library/scala/collection/concurrent/TrieMap.scala @@ -1011,8 +1011,11 @@ private[collection] class TrieMapIterator[K, V](var level: Int, private var ct: */ protected def subdivide(): Seq[Iterator[(K, V)]] = if (subiter ne null) { // the case where an LNode is being iterated - val it = subiter - subiter = null + val it = newIterator(level + 1, ct, _mustInit = false) + it.depth = -1 + it.subiter = this.subiter + it.current = null + this.subiter = null advance() this.level += 1 Seq(it, this) diff --git a/test/files/run/t7498.scala b/test/files/run/t7498.scala new file mode 100644 index 0000000000..1dbf0597e0 --- /dev/null +++ b/test/files/run/t7498.scala @@ -0,0 +1,20 @@ + + + + + + + +object Test extends App { + import scala.collection.concurrent.TrieMap + + class Collision(val idx: Int) { + override def hashCode = idx % 10 + } + + val tm = TrieMap[Collision, Unit]() + for (i <- 0 until 1000) tm(new Collision(i)) = () + + tm.par.foreach(kv => ()) +} + |