Scala Programming Language
  1. Scala Programming Language
  2. SI-6633

ListBuffer is corrupted after insert with position > length

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.2, Scala 2.10.0-RC1, Scala 2.10.0-RC2, Scala 2.10.0, Scala 2.11.0
    • Fix Version/s: Scala 2.10.0
    • Component/s: Collections
    • Environment:

      Scala version 2.11.0-20121010-013641-9bedb07350

      Description

      The insert fails correctly ...

      scala> import collection.mutable.ListBuffer
      import collection.mutable.ListBuffer
      
      scala> val lb = ListBuffer('a, 'b , 'c)
      lb: scala.collection.mutable.ListBuffer[Symbol] = ListBuffer('a, 'b, 'c)
      
      scala> lb.insert(9, 'x)
      java.lang.IndexOutOfBoundsException: 9
      	at scala.collection.mutable.ListBuffer.insertAll(ListBuffer.scala:249)
      	at scala.collection.mutable.BufferLike$class.insert(BufferLike.scala:166)
      	at scala.collection.mutable.AbstractBuffer.insert(Buffer.scala:48)
      

      ... but the buffer instance is corrupted afterwards:

      scala> lb
      java.util.NoSuchElementException: head of empty list
      	at scala.collection.immutable.Nil$.head(List.scala:329)
      	at scala.collection.immutable.Nil$.head(List.scala:326)
      	at scala.collection.mutable.ListBuffer$$anon$1.next(ListBuffer.scala:406)
      	at scala.collection.Iterator$$anon$10.next(Iterator.scala:312)
      	at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
      	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      	at scala.collection.AbstractIterator.foreach(Iterator.scala:1156)
      	at scala.collection.TraversableOnce$class.addString(TraversableOnce.scala:306)
      	at scala.collection.AbstractIterator.addString(Iterator.scala:1156)
      	at scala.collection.TraversableOnce$class.mkString(TraversableOnce.scala:272)
      	at scala.collection.AbstractIterator.mkString(Iterator.scala:1156)
      	at scala.runtime.ScalaRunTime$.scala$runtime$ScalaRunTime$$inner$1(ScalaRunTime.scala:323)
      	at scala.runtime.ScalaRunTime$.stringOf(ScalaRunTime.scala:332)
      	at scala.runtime.ScalaRunTime$.replStringOf(ScalaRunTime.scala:340)
      
      scala> println(lb)
      ListBuffer('a, 'b, 'c)
      
      scala> lb.length
      res16: Int = 4
      

        Issue Links

          Activity

          Hide
          Simon Ochsenreither added a comment -

          The fix for SI-6632 could probably be enough to fix this, too.

          Show
          Simon Ochsenreither added a comment - The fix for SI-6632 could probably be enough to fix this, too.
          Show
          Simon Ochsenreither added a comment - Merged in https://github.com/scala/scala/commit/522ef796c8466d24fe7068af0bd1c8989b29b392

            People

            • Assignee:
              Simon Ochsenreither
              Reporter:
              Simon Ochsenreither
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development