scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Stringification of XML values causes StackOverflowError #7658

Closed scabug closed 11 years ago

scabug commented 11 years ago

I started to see two new test failures on Avian, but the issue exists on all runtimes.

The code ends up in an endless recursion by the changes to the stringOf method in ScalaRuntime (https://github.com/scala/scala/commit/739cc9d1ad8b7d1def468299c9cdc6e9ebb2d143#src/library/scala/runtime/ScalaRunTime.scala).

The reason why it seems to work fine on Hotsopt is just that Hotspot copes better with StackOverflowErrors than Avian and is in a less broken state after catching the SOE:

    try inner(arg)
    catch {
      case _: StackOverflowError | _: UnsupportedOperationException | _: AssertionError => "" + arg
    }

Don't be mistaken: Even on Hotspot stringifying XML values causes SOEs which are then catched and thrown away.

Stacktraces look like this:

...
scala> val atom = new scala.xml.Atom()
java.lang.ExceptionInInitializerError
at scala.xml.Node.buildString(Node.scala:162)
at scala.runtime.ScalaRunTime$.scala$runtime$ScalaRunTime$$inner$1(ScalaRunTime.scala:313)
at scala.collection.Iterator$class.foreach(Iterator.scala:743)
at scala.collection.TraversableOnce$class.addString(TraversableOnce.scala:343)
at scala.collection.TraversableOnce$class.mkString(TraversableOnce.scala:309)
at scala.runtime.ScalaRunTime$.scala$runtime$ScalaRunTime$$inner$1(ScalaRunTime.scala:316)
at scala.collection.Iterator$class.foreach(Iterator.scala:743)
at scala.collection.TraversableOnce$class.addString(TraversableOnce.scala:343)
at scala.collection.TraversableOnce$class.mkString(TraversableOnce.scala:309)
...

or

...
java.lang.NoClassDefFoundError: scala.xml.Utility$
at scala.xml.Node.buildString(Node.scala:162)
at scala.runtime.ScalaRunTime$.scala$runtime$ScalaRunTime$$inner$1(ScalaRunTime.scala:313)
at scala.collection.Iterator$class.foreach(Iterator.scala:743)
at scala.collection.TraversableOnce$class.addString(TraversableOnce.scala:343)
at scala.collection.TraversableOnce$class.mkString(TraversableOnce.scala:309)
at scala.runtime.ScalaRunTime$.scala$runtime$ScalaRunTime$$inner$1(ScalaRunTime.scala:316)
at scala.collection.Iterator$class.foreach(Iterator.scala:743)
...
Caused by: java.lang.StackOverflowError
... 10888 more
scabug commented 11 years ago

Imported From: https://issues.scala-lang.org/browse/SI-7658?orig=1 Reporter: @soc Affected Versions: 2.11.0-M4

scabug commented 11 years ago

@adriaanm said: https://github.com/scala/scala/pull/2803