Skip to content
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"

// used in CompilerErrors test
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % "test"

// temporary workaround with scala-xml compiler dependency
fork in Test := true
10 changes: 9 additions & 1 deletion src/main/scala/scala/xml/pull/XMLEventReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,19 @@ class XMLEventReader(src: Source)

override def run() {
curInput = input
interruptibly { this.initialize.document() }
try {
interruptibly { this.initialize.document() }
} catch {
case e:Exception => setEvent(ExceptionEvent(e))
}
setEvent(POISON)
}
}
}

// An internal class used to propagate exception from helper threads to API end users.
private case class ExceptionEvent(exception:Exception) extends XMLEvent

// An iterator designed for one or more producers to generate
// elements, and a single consumer to iterate. Iteration will continue
// until closeIterator() is called, after which point producers
Expand Down Expand Up @@ -143,6 +150,7 @@ trait ProducerConsumerIterator[T >: Null] extends Iterator[T] {
def next() = {
if (eos()) throw new NoSuchElementException("ProducerConsumerIterator")
if (buffer == null) fillBuffer()
if (buffer.isInstanceOf[ExceptionEvent]) throw buffer.asInstanceOf[ExceptionEvent].exception

drainBuffer()
}
Expand Down
20 changes: 19 additions & 1 deletion src/test/scala/scala/xml/pull/XMLEventReaderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,22 @@ class XMLEventReaderTest {
er.stop // allow thread to be garbage-collected
}

}
@Test(expected = classOf[Exception])
def missingTagTest: Unit = {
val data=
"""<?xml version="1.0" ?>
|<verbosegc xmlns="http://www.ibm.com/j9/verbosegc">
|
|<initialized id="1" timestamp="2013-10-04T00:11:08.389">
|</initialized>
|
|<exclusive-start id="2" timestamp="2013-10-04T00:11:09.185" intervalms="796.317">
|<response-info timems="0.007" idlems="0.007" threads="0" />
|</exclusive-start>
|""".stripMargin

val er = new XMLEventReader(Source.fromString(data))
while(er.hasNext) er.next()
er.stop()
}
}