From 2dfbbf55688d17fd3daa15341da878b98783ba3c Mon Sep 17 00:00:00 2001 From: Rex Kerr Date: Wed, 15 Jan 2014 20:16:39 -0800 Subject: SI-8154 AnyRefMap iterates its way to ((null, null)) Changed logic to prevent mutation between hasNext and next from delivering invalid results. Also fixed superscripts in scaladoc. --- .../scala/collection/SetMapConsistencyTest.scala | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/junit/scala/collection/SetMapConsistencyTest.scala b/test/junit/scala/collection/SetMapConsistencyTest.scala index 7bb8ca958b..0d6f43db06 100644 --- a/test/junit/scala/collection/SetMapConsistencyTest.scala +++ b/test/junit/scala/collection/SetMapConsistencyTest.scala @@ -478,7 +478,7 @@ class SetMapConsistencyTest { } @Test - def si8213() { + def testSI8213() { val am = new scala.collection.mutable.AnyRefMap[String, Int] for (i <- 0 until 1024) am += i.toString -> i am.getOrElseUpdate("1024", { am.clear; -1 }) @@ -488,4 +488,23 @@ class SetMapConsistencyTest { lm.getOrElseUpdate(1024, { lm.clear; -1 }) assert(lm == scala.collection.mutable.LongMap(1024L -> -1)) } + + // Mutating when an iterator is in the wild shouldn't produce random junk in the iterator + // Todo: test all sets/maps this way + @Test + def testSI8154() { + def f() = { + val xs = scala.collection.mutable.AnyRefMap[String, Int]("a" -> 1) + val it = xs.iterator + it.hasNext + xs.clear() + + if (it.hasNext) Some(it.next) + else None + } + assert(f() match { + case Some((a,b)) if (a==null || b==null) => false + case _ => true + }) + } } -- cgit v1.2.3