diff --git a/jvm/src/test/scala/scala/xml/XMLTest.scala b/jvm/src/test/scala/scala/xml/XMLTest.scala index 5bad0fb3..4e5dba1a 100644 --- a/jvm/src/test/scala/scala/xml/XMLTest.scala +++ b/jvm/src/test/scala/scala/xml/XMLTest.scala @@ -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("") + XML.adapter.loadDocument(Source.fromString(""), reader) } catch { case _: org.xml.sax.SAXParseException => } diff --git a/shared/src/main/scala/scala/xml/factory/XMLLoader.scala b/shared/src/main/scala/scala/xml/factory/XMLLoader.scala index afe54330..47ee3708 100644 --- a/shared/src/main/scala/scala/xml/factory/XMLLoader.scala +++ b/shared/src/main/scala/scala/xml/factory/XMLLoader.scala @@ -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