Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListBuffer is corrupted after insert with position > length #6633

Closed
scabug opened this issue Nov 9, 2012 · 3 comments
Closed

ListBuffer is corrupted after insert with position > length #6633

scabug opened this issue Nov 9, 2012 · 3 comments

Comments

@scabug
Copy link

scabug commented Nov 9, 2012

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
@scabug
Copy link
Author

scabug commented Nov 9, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6633?orig=1
Reporter: @soc
Affected Versions: 2.9.2, 2.10.0-RC1, 2.10.0-RC2, 2.10.0, 2.11.0
See #6632

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@soc said:
The fix for #6632 could probably be enough to fix this, too.

@scabug
Copy link
Author

scabug commented Nov 24, 2012

@soc said:
Merged in scala/scala@522ef79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants