This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Mismatched StringBuilder behaviour on appending null

No replies
Chris Marshall
Joined: 2009-06-17,
User offline. Last seen 44 weeks 3 days ago.
I would think that it was a reasonable assumption that the following are equivalent
s1 : Strings2 : String
(s1 + s2) === ((new StringBuilder) ++= s1 ++= s2).toString
In Java, I believe that this is the case. However, in scala, we have:
scala> (new StringBuilder) ++= (null : String)java.lang.NullPointerException at scala.collection.immutable.StringLike$class.length(StringLike.scala:56) at scala.collection.immutable.StringOps.length(StringOps.scala:31) at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33) at scala.collection.immutable.StringOps.foreach(StringOps.scala:31) at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48) at scala.collection.mutable.StringBuilder.$plus$plus$eq(StringBuilder.scala:26)
Would this be classified as a bug?
Chris


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland