diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2012-11-16 01:18:08 +0100 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2012-11-16 23:11:55 +0100 |
commit | 2c23acf39e810fd43f9ce5af0a4c3e4d952f2081 (patch) | |
tree | e383e24325253e2985706c62e77c6f5f23f2977a /test/files | |
parent | c264898205efc10961a972bdd689c7e65dc25578 (diff) | |
download | scala-2c23acf39e810fd43f9ce5af0a4c3e4d952f2081.tar.gz scala-2c23acf39e810fd43f9ce5af0a4c3e4d952f2081.tar.bz2 scala-2c23acf39e810fd43f9ce5af0a4c3e4d952f2081.zip |
SI-6634 Fixes data corruption issue in ListBuffer#remove
This is the cut-down version with minimally invasive changes,
e. g. keeping the "auto-correcting" bounds algorithm.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/t6634.check | 31 | ||||
-rw-r--r-- | test/files/run/t6634.scala | 80 |
2 files changed, 111 insertions, 0 deletions
diff --git a/test/files/run/t6634.check b/test/files/run/t6634.check new file mode 100644 index 0000000000..f6cbb30c67 --- /dev/null +++ b/test/files/run/t6634.check @@ -0,0 +1,31 @@ +Trying lb0 ... +Checking ... +String OK. +Length OK. + +Trying lb1 ... +Checking ... +String OK. +Length OK. + +Trying lb2 ... +Checking ... +String OK. +Length OK. + +Trying lb3 ... +Checking ... +String OK. +Length OK. + +Trying lb4 ... +Checking ... +String OK. +Length OK. + +Trying lb5 ... +java.lang.IllegalArgumentException: removing negative number (-1) of elements +Checking ... +String OK. +Length OK. + diff --git a/test/files/run/t6634.scala b/test/files/run/t6634.scala new file mode 100644 index 0000000000..759e6d519d --- /dev/null +++ b/test/files/run/t6634.scala @@ -0,0 +1,80 @@ +import collection.mutable.ListBuffer + +object Test extends App { + def newLB = ListBuffer('a, 'b, 'c, 'd, 'e) + + val lb0 = newLB + println("Trying lb0 ...") + try { + lb0.remove(5, 0) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IndexOutOfBoundsException => println(ex) + } + checkNotCorrupted(lb0) + + val lb1 = newLB + println("Trying lb1 ...") + try { + lb1.remove(6, 6) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IndexOutOfBoundsException => println(ex) + } + checkNotCorrupted(lb1) + + val lb2 = newLB + println("Trying lb2 ...") + try { + lb2.remove(99, 6) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IndexOutOfBoundsException => println(ex) + } + checkNotCorrupted(lb2) + + val lb3 = newLB + println("Trying lb3 ...") + try { + lb3.remove(1, 9) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IllegalArgumentException => println(ex) + } + checkNotCorrupted(lb3, "ListBuffer('a)", 1) + + val lb4 = newLB + println("Trying lb4 ...") + try { + lb4.remove(-1, 1) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IndexOutOfBoundsException => println(ex) + } + checkNotCorrupted(lb4, "ListBuffer('b, 'c, 'd, 'e)", 4) + + val lb5 = newLB + println("Trying lb5 ...") + try { + lb5.remove(1, -1) + } catch { + case ex: IllegalArgumentException => println(ex) + } + checkNotCorrupted(lb5) + + // buffer should neither be changed nor corrupted after calling remove with invalid arguments + def checkNotCorrupted( + lb: ListBuffer[Symbol], + expectedString: String = "ListBuffer('a, 'b, 'c, 'd, 'e)", + expectedLength: Int = 5) = { + println("Checking ...") + val replStr = scala.runtime.ScalaRunTime.replStringOf(lb, 100) + if (replStr == expectedString + "\n") println("String OK.") + else println("!!! replStringOf FAILED: " + replStr) + + val len = lb.length + if (len == expectedLength) println("Length OK.") + else println("!!! length FAILED: " + len) + println() + } +}
\ No newline at end of file |