File tree 2 files changed +28
-2
lines changed
main/scala/scala/xml/pull
test/scala/scala/xml/pull
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -92,12 +92,19 @@ class XMLEventReader(src: Source)
92
92
93
93
override def run () {
94
94
curInput = input
95
- interruptibly { this .initialize.document() }
95
+ try {
96
+ interruptibly { this .initialize.document() }
97
+ } catch {
98
+ case e: Exception => setEvent(ExceptionEvent (e))
99
+ }
96
100
setEvent(POISON )
97
101
}
98
102
}
99
103
}
100
104
105
+ // An internal class used to propagate exception from helper threads to API end users.
106
+ private case class ExceptionEvent (exception: Exception ) extends XMLEvent
107
+
101
108
// An iterator designed for one or more producers to generate
102
109
// elements, and a single consumer to iterate. Iteration will continue
103
110
// until closeIterator() is called, after which point producers
@@ -143,6 +150,7 @@ trait ProducerConsumerIterator[T >: Null] extends Iterator[T] {
143
150
def next () = {
144
151
if (eos()) throw new NoSuchElementException (" ProducerConsumerIterator" )
145
152
if (buffer == null ) fillBuffer()
153
+ if (buffer.isInstanceOf [ExceptionEvent ]) throw buffer.asInstanceOf [ExceptionEvent ].exception
146
154
147
155
drainBuffer()
148
156
}
Original file line number Diff line number Diff line change @@ -40,4 +40,22 @@ class XMLEventReaderTest {
40
40
er.stop // allow thread to be garbage-collected
41
41
}
42
42
43
- }
43
+ @ Test (expected = classOf [Exception ])
44
+ def missingTagTest : Unit = {
45
+ val data =
46
+ """ <?xml version="1.0" ?>
47
+ |<verbosegc xmlns="http://www.ibm.com/j9/verbosegc">
48
+ |
49
+ |<initialized id="1" timestamp="2013-10-04T00:11:08.389">
50
+ |</initialized>
51
+ |
52
+ |<exclusive-start id="2" timestamp="2013-10-04T00:11:09.185" intervalms="796.317">
53
+ |<response-info timems="0.007" idlems="0.007" threads="0" />
54
+ |</exclusive-start>
55
+ |""" .stripMargin
56
+
57
+ val er = new XMLEventReader (Source .fromString(data))
58
+ while (er.hasNext) er.next()
59
+ er.stop()
60
+ }
61
+ }
You can’t perform that action at this time.
0 commit comments