Aladdin - Scala Bugtracking
[#1199] project: api priority: low category: bug
submitter assigned to status date submitted
Nikolay Burak fixed 2007-07-06 12:05:51.0
subject [contrib #676] infinit loop in scala.xml.PrettyPrinter
code
import scala.xml._;

object PrettyPrint extends Application {
  override def main(args : Array[String]) {
	val x = <td align="center" colspan="1" nowrap="nowrap" rowspan="1" valign="top" height="25"></td>

  println(new PrettyPrinter(79,3).format(x)); // works ok
  println(new PrettyPrinter(81,3).format(x)); // works ok
  println(new PrettyPrinter(80,3).format(x)); // loops infinitely because xml string hits an edge case with width 80
  }
}
what happened
third println loops infinitely, eventually getting an OutOfMemoryError
what expected should pretty print properly and terminate. I believe there is a bug in scala.xml.PrettyPrinter.cut() The loop starting at line 63 while (i < tmp) { last = i::last i = s.indexOf(' ', i) } is the culprit as s.indexOf(' ',i) will always return i. But I do not know the proper fix as merely changing it to s.indexOf(' ',i+1) is insufficient as eventully i will be -1.
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-07-06 12:06:24.0
Burak  edited on  2007-07-06 16:31:20.0
i fixed it, it's strange code that needs to be redone.