Skip to content

Commit

Permalink
Call reset on reusable SAXParser instance
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Nov 11, 2024
1 parent e2b3913 commit 063c03a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions jvm/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,14 @@ class XMLTestJVM {
@UnitTest
def checkThatErrorHandlerIsNotOverwritten(): Unit = {
var gotAnError: Boolean = false
XML.reader.setErrorHandler(new org.xml.sax.ErrorHandler {
val reader = XML.reader
reader.setErrorHandler(new org.xml.sax.ErrorHandler {
override def warning(e: SAXParseException): Unit = gotAnError = true
override def error(e: SAXParseException): Unit = gotAnError = true
override def fatalError(e: SAXParseException): Unit = gotAnError = true
})
try {
XML.loadString("<a>")
XML.adapter.loadDocument(Source.fromString("<a>"), reader)
} catch {
case _: org.xml.sax.SAXParseException =>
}
Expand Down
6 changes: 5 additions & 1 deletion shared/src/main/scala/scala/xml/factory/XMLLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ trait XMLLoader[T <: Node] {
}

/* Override this to use a different SAXParser. */
def parser: SAXParser = parserInstance.get
def parser: SAXParser = {
val p = parserInstance.get
p.reset()
p
}

/* Override this to use a different XMLReader. */
def reader: XMLReader = parser.getXMLReader
Expand Down

0 comments on commit 063c03a

Please sign in to comment.