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

Why does this not terminate?

1 reply
Tupshin Harper
Joined: 2009-02-10,
User offline. Last seen 42 years 45 weeks ago.

The following works exactly as I would expect until the end of the XML
file. When it is done, er.hasNext blocks, waiting for...something,
instead of returning false.
1) why???
2) is there a different way I should be iterating through the events?
for (evt <- er ) does the same thing, of course.

package foo.bar

import scala.xml._
import scala.xml.pull._
import scala.io.Source

object TestParse {
def main(args : Array[String]) : Unit = {
val src = Source.fromFile("test.xml")
val er = new XMLEventReader().initialize(src);
while (er.hasNext) {
println(er.next)
}
}
}

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Why does this not terminate?

On Tue, Apr 28, 2009 at 05:44:13PM -0700, Tupshin Harper wrote:
> The following works exactly as I would expect until the end of the XML
> file. When it is done, er.hasNext blocks, waiting for...something,
> instead of returning false. 1) why???

Let's take a look at the ol' hasNext implementation:

def hasNext = true

Not so good for a while loop. However that is indeed the ol'
implementation as I checked in a whole new parser today and now it is:

def hasNext() = !eos && (buffer != null || fillBuffer)

Please try out the parser and let me know if it does good things (I
imagine tonight's nightly build will have it.) I give my hasNext a
slightly better chance of terminating, but one can never be too sure
when it comes to halting problems.

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