- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Mismatched StringBuilder behaviour on appending null
Fri, 2011-03-25, 18:35
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
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