Skip to content

SI-4267 - fix to avoid XMLEventReader swallows IO/Parse exception #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}