Skip to content

Commit

Permalink
Merge pull request #10146 from geoand/testsource-close
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi authored Jun 23, 2020
2 parents e2bbfdb + 8394406 commit a002dcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte
}
}

class ExtensionState implements ExtensionContext.Store.CloseableResource {
class ExtensionState {

private final Closeable testResourceManager;
private final Closeable resource;
Expand All @@ -685,7 +685,6 @@ class ExtensionState implements ExtensionContext.Store.CloseableResource {
this.resource = resource;
}

@Override
public void close() throws Throwable {
try {
resource.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
*/
public class XStreamDeepClone implements DeepClone {

private final XStream xStream;
private final Supplier<XStream> xStreamSupplier;

public XStreamDeepClone(ClassLoader classLoader) {
xStream = new XStream();
XStream.setupDefaultSecurity(xStream);
xStream.allowTypesByRegExp(new String[] { ".*" });
xStream.setClassLoader(classLoader);
// avoid doing any work eagerly since the cloner is rarely used
xStreamSupplier = () -> {
XStream result = new XStream();
XStream.setupDefaultSecurity(result);
result.allowTypesByRegExp(new String[] { ".*" });
result.setClassLoader(classLoader);
return result;
};
}

public Object clone(Object objectToClone) {
Expand All @@ -40,6 +44,7 @@ public Object get() {
}

private Object doClone(Object objectToClone) {
XStream xStream = xStreamSupplier.get();
final String serialized = xStream.toXML(objectToClone);
final Object result = xStream.fromXML(serialized);
if (result == null) {
Expand Down

0 comments on commit a002dcf

Please sign in to comment.