diff options
author | Denton Cockburn <kanielc@gmail.com> | 2015-01-31 11:22:57 -0500 |
---|---|---|
committer | Denton Cockburn <kanielc@gmail.com> | 2015-01-31 11:22:57 -0500 |
commit | f2d0231898a4537218656867e9356e09d05d3a85 (patch) | |
tree | bb6e08bb3bd17337400025e9b9b53c3d6450fc8c /test | |
parent | 5d7098c629bbb7cc0ab7e74c235bd4afca3de24e (diff) | |
download | scala-f2d0231898a4537218656867e9356e09d05d3a85.tar.gz scala-f2d0231898a4537218656867e9356e09d05d3a85.tar.bz2 scala-f2d0231898a4537218656867e9356e09d05d3a85.zip |
SI-9095 Memory leak in LinkedHasMap and LinkedHashSet
The clear() method in scala.collection.mutable.LinkedHashSet and
scala.collection.mutable.LinkedHashMap does not set lastEntry to null.
In result it holds a reference to an object that was removed from the
collection.
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/collection/mutable/LinkedHashMapTest.scala | 25 | ||||
-rw-r--r-- | test/junit/scala/collection/mutable/LinkedHashSetTest.scala | 25 |
2 files changed, 50 insertions, 0 deletions
diff --git a/test/junit/scala/collection/mutable/LinkedHashMapTest.scala b/test/junit/scala/collection/mutable/LinkedHashMapTest.scala new file mode 100644 index 0000000000..37dcd028a5 --- /dev/null +++ b/test/junit/scala/collection/mutable/LinkedHashMapTest.scala @@ -0,0 +1,25 @@ +package scala.collection.mutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.{ Assert, Test } + +import scala.collection.mutable + +/* Test for SI-9095 */ +@RunWith(classOf[JUnit4]) +class LinkedHashMapTest { + class TestClass extends mutable.LinkedHashMap[String, Int] { + def lastItemRef = lastEntry + } + + @Test + def testClear: Unit = { + val lhm = new TestClass + Seq("a" -> 8, "b" -> 9).foreach(kv => lhm.put(kv._1, kv._2)) + + Assert.assertNotNull(lhm.lastItemRef) + lhm.clear() + Assert.assertNull(lhm.lastItemRef) + } +} diff --git a/test/junit/scala/collection/mutable/LinkedHashSetTest.scala b/test/junit/scala/collection/mutable/LinkedHashSetTest.scala new file mode 100644 index 0000000000..b419ad37ec --- /dev/null +++ b/test/junit/scala/collection/mutable/LinkedHashSetTest.scala @@ -0,0 +1,25 @@ +package scala.collection.mutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.{ Assert, Test } + +import scala.collection.mutable + +/* Test for SI-9095 */ +@RunWith(classOf[JUnit4]) +class LinkedHashSetTest { + class TestClass extends mutable.LinkedHashSet[String] { + def lastItemRef = lastEntry + } + + @Test + def testClear: Unit = { + val lhs = new TestClass + Seq("a", "b").foreach(k => lhs.add(k)) + + Assert.assertNotNull(lhs.lastItemRef) + lhs.clear() + Assert.assertNull(lhs.lastItemRef) + } +} |