diff options
author | Rex Kerr <ichoran@gmail.com> | 2014-01-30 11:43:26 -0800 |
---|---|---|
committer | Rex Kerr <ichoran@gmail.com> | 2014-01-30 11:47:05 -0800 |
commit | f97e2d42eb211d429b27f79fe993bf48c92e9740 (patch) | |
tree | 876b10816206ff8180e572804bb101464f560b2c /test/junit | |
parent | 0e578e693196f93b1ba4f972a2c96d468bef464a (diff) | |
download | scala-f97e2d42eb211d429b27f79fe993bf48c92e9740.tar.gz scala-f97e2d42eb211d429b27f79fe993bf48c92e9740.tar.bz2 scala-f97e2d42eb211d429b27f79fe993bf48c92e9740.zip |
SI-8213 AnyRefMap.getOrElseUpdate is faulty
Altered getOrElseUpdate to be robust to the map changing out from under it as a result of calling the default value method. Side-effects FTW!
Made a comparable change in LongMap also, as it was also affected. And added a test to SetMapConsistencyTest.
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/collection/SetMapConsistencyTest.scala | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/junit/scala/collection/SetMapConsistencyTest.scala b/test/junit/scala/collection/SetMapConsistencyTest.scala index c62b074483..7bb8ca958b 100644 --- a/test/junit/scala/collection/SetMapConsistencyTest.scala +++ b/test/junit/scala/collection/SetMapConsistencyTest.scala @@ -476,4 +476,16 @@ class SetMapConsistencyTest { } assert(test) } + + @Test + def si8213() { + val am = new scala.collection.mutable.AnyRefMap[String, Int] + for (i <- 0 until 1024) am += i.toString -> i + am.getOrElseUpdate("1024", { am.clear; -1 }) + assert(am == scala.collection.mutable.AnyRefMap("1024" -> -1)) + val lm = new scala.collection.mutable.LongMap[Int] + for (i <- 0 until 1024) lm += i.toLong -> i + lm.getOrElseUpdate(1024, { lm.clear; -1 }) + assert(lm == scala.collection.mutable.LongMap(1024L -> -1)) + } } |