Skip to content

Commit

Permalink
Clean-up data stacks in UnmarshallingContext implementations in case …
Browse files Browse the repository at this point in the history
…of exception. Originally provided by Märt Bakhoff. Closes #91 and #106.
  • Loading branch information
joehni committed Jan 30, 2018
1 parent 18c3408 commit bd71ca4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions xstream-distribution/src/content/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ <h1 id="upcoming-1.4.x">Upcoming 1.4.x maintenance release</h1>
<h2>Minor changes</h2>

<ul>
<li>GHPR:#91, GHPR:#106: Clean-up data stacks in UnmarshallingContext implementations in case of exception (by
Märt Bakhoff).</li>
<li>GHI:#2: Unneeded contention in DefaultConverterLookup.</li>
<li>GHI:#94: Fix PathConverter containing absolute Windows paths.</li>
<li>JIRA:XSTR-616 and GHPR:#93: Introduce StringCodec interface to support arbitrary Base64 codec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2006, 2007, 2008, 2011, 2014, 2015 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2011, 2014, 2015, 2018 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -71,11 +71,16 @@ protected Object convert(final Object parent, final Class<?> type, final Convert
} else {
final R currentReferenceKey = getCurrentReferenceKey();
parentStack.push(currentReferenceKey);
result = super.convert(parent, type, converter);
if (currentReferenceKey != null) {
values.put(currentReferenceKey, result == null ? NULL : result);
Object localResult = null;
try {
localResult = super.convert(parent, type, converter);
} finally {
result = localResult;
if (currentReferenceKey != null) {
values.put(currentReferenceKey, result == null ? NULL : result);
}
parentStack.popSilently();
}
parentStack.popSilently();
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014, 2015 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014, 2015, 2018 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -58,7 +58,7 @@ public Object convertAnother(final Object parent, Class<?> type, Converter conve
converter = converterLookup.lookupConverterForType(type);
} else {
if (!converter.canConvert(type)) {
final ConversionException e = new ConversionException("Explicit selected converter cannot handle type");
final ConversionException e = new ConversionException("Explicitly selected converter cannot handle type");
e.add("item-type", type.getName());
e.add("converter-type", converter.getClass().getName());
throw e;
Expand All @@ -68,18 +68,18 @@ public Object convertAnother(final Object parent, Class<?> type, Converter conve
}

protected Object convert(final Object parent, final Class<?> type, final Converter converter) {
types.push(type);
try {
types.push(type);
final Object result = converter.unmarshal(reader, this);
types.popSilently();
return result;
return converter.unmarshal(reader, this);
} catch (final ConversionException conversionException) {
addInformationTo(conversionException, type, converter, parent);
throw conversionException;
} catch (final RuntimeException e) {
final ConversionException conversionException = new ConversionException(e);
addInformationTo(conversionException, type, converter, parent);
throw conversionException;
} finally {
types.popSilently();
}
}

Expand Down

0 comments on commit bd71ca4

Please sign in to comment.