Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

ListBuffer misbehaves after clear #362

Closed
lrytz opened this issue Jan 24, 2018 · 0 comments
Closed

ListBuffer misbehaves after clear #362

lrytz opened this issue Jan 24, 2018 · 0 comments

Comments

@lrytz
Copy link
Member

lrytz commented Jan 24, 2018

Example 1:

scala> val b = collection.mutable.ListBuffer.empty[String]
b: scala.collection.mutable.ListBuffer[String] = ListBuffer()

scala> b += "a"
res0: b.type = ListBuffer(a)

scala> b.clear()

scala> b += "b"
res2: b.type = ListBuffer()

scala> b
res3: scala.collection.mutable.ListBuffer[String] = ListBuffer()

Example 2:

scala> val b = collection.mutable.ListBuffer.empty[String]
b: scala.collection.mutable.ListBuffer[String] = ListBuffer()

scala> b += "a"
res0: b.type = ListBuffer(a)

scala> b.toList
res1: List[String] = List(a)

scala> b.clear()

scala> b += "b"
java.lang.NullPointerException
  at scala.collection.mutable.ListBuffer.addOne(ListBuffer.scala:102)
  at scala.collection.mutable.ListBuffer.addOne(ListBuffer.scala:34)
  at scala.collection.mutable.Growable.$plus$eq(Growable.scala:28)
  at scala.collection.mutable.Growable.$plus$eq$(Growable.scala:28)
  at scala.collection.mutable.ListBuffer.$plus$eq(ListBuffer.scala:34)

This causes test failures in scala-xml (https://github.com/scala/scala-xml/compare/master...lrytz:newCollections?expand=1)

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

No branches or pull requests

2 participants