Skip to content

Commit

Permalink
Fix leakage of system property setting Stax parser. Closes x-stream#283.
Browse files Browse the repository at this point in the history
  • Loading branch information
joehni committed Feb 4, 2022
1 parent 875e0a9 commit 07ee8a0
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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", "<?xml version='1.0' encoding='utf-8'?><string>Hi</string>");
assertTrue(driver.createStaxReaderCalled);
assertTrue(driver.createStaxWriterCalled);
try {
final MyStaxDriver driver = new MyStaxDriver();
xstream = new XStream(driver);
assertBothWays("Hi", "<?xml version='1.0' encoding='utf-8'?><string>Hi</string>");
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());
}
}
}
}

0 comments on commit 07ee8a0

Please sign in to comment.