From 674e0f80016dd70cd04c533daceeaa12161dae17 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Tue, 4 Sep 2012 11:01:44 -0400 Subject: Fix t6114 - ++ on JList wrapper modifies underlying collection. We solve this by overriding clone for JListWrapper to actually do a full clone. Note: This fix may need to be included other places, *but* we're not sure we've cloned the collection sensibly. I.e. is ArrayList a good default? --- test/files/run/t6114.scala | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/files/run/t6114.scala (limited to 'test/files/run/t6114.scala') diff --git a/test/files/run/t6114.scala b/test/files/run/t6114.scala new file mode 100644 index 0000000000..cb880ece00 --- /dev/null +++ b/test/files/run/t6114.scala @@ -0,0 +1,61 @@ +object Test extends App { + def testList = { + val list = new java.util.ArrayList[Int] + list.add(1) + list.add(2) + list.add(3) + import scala.collection.JavaConverters._ + val next = list.asScala ++ List(4,5,6) + assert(next != list.asScala) + + val raw = list.asScala + val cloned = raw.clone + list.add(1) + assert(raw != cloned) + } + def testSet = { + val set = new java.util.HashSet[Int] + set.add(1) + set.add(2) + set.add(3) + import scala.collection.JavaConverters._ + val next = set.asScala ++ Set(4,5,6) + assert(next != set.asScala) + + val raw = set.asScala + val cloned = raw.clone + set.add(4) + assert(raw != cloned) + } + def testMap = { + val map = new java.util.HashMap[Int,Int] + map.put(1,1) + map.put(2,2) + map.put(3,3) + import scala.collection.JavaConverters._ + val next = map.asScala ++ Map(4->4,5->5,6->6) + assert(next != map.asScala) + + val raw = map.asScala + val cloned = raw.clone + map.put(4,4) + assert(raw != cloned) + } + + def testCollection = { + val list: java.util.Collection[Int] = new java.util.ArrayDeque[Int] + list.add(1) + list.add(2) + list.add(3) + import scala.collection.JavaConverters._ + val next = list.asScala ++ List(4,5,6) + assert(next != list.asScala) + + // Note: Clone is hidden at this level, so no overriden cloning. + } + + testList + testSet + testMap + testCollection +} -- cgit v1.2.3