diff --git a/xstream/src/test/com/thoughtworks/xstream/io/xml/StaxDriverTest.java b/xstream/src/test/com/thoughtworks/xstream/io/xml/StaxDriverTest.java
index f10cd1851..34c80614d 100644
--- a/xstream/src/test/com/thoughtworks/xstream/io/xml/StaxDriverTest.java
+++ b/xstream/src/test/com/thoughtworks/xstream/io/xml/StaxDriverTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2018 XStream Committers.
+ * Copyright (C) 2006, 2007, 2018, 2022 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -49,12 +49,27 @@ public AbstractPullReader createStaxReader(final XMLStreamReader in) {
}
public void testCanOverloadStaxReaderAndWriterInstantiation() {
+ final String staxInput = System.getProperty(XMLInputFactory.class.getName());
+ final String staxOutput = System.getProperty(XMLOutputFactory.class.getName());
System.setProperty(XMLInputFactory.class.getName(), MXParserFactory.class.getName());
System.setProperty(XMLOutputFactory.class.getName(), XMLOutputFactoryBase.class.getName());
- final MyStaxDriver driver = new MyStaxDriver();
- xstream = new XStream(driver);
- assertBothWays("Hi", "Hi");
- assertTrue(driver.createStaxReaderCalled);
- assertTrue(driver.createStaxWriterCalled);
+ try {
+ final MyStaxDriver driver = new MyStaxDriver();
+ xstream = new XStream(driver);
+ assertBothWays("Hi", "Hi");
+ assertTrue(driver.createStaxReaderCalled);
+ assertTrue(driver.createStaxWriterCalled);
+ } finally {
+ if (staxInput != null) {
+ System.setProperty(XMLInputFactory.class.getName(), staxInput);
+ } else {
+ System.clearProperty(XMLInputFactory.class.getName());
+ }
+ if (staxOutput != null) {
+ System.setProperty(XMLOutputFactory.class.getName(), staxOutput);
+ } else {
+ System.clearProperty(XMLOutputFactory.class.getName());
+ }
+ }
}
}