Skip to content

Commit 08f0810

Browse files
committed
Avoid 2nd CustomObjectoutputStream in marshalling process.
1 parent ce95902 commit 08f0810

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

xstream/src/java/com/thoughtworks/xstream/XStream.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
3-
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 XStream Committers.
3+
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 XStream Committers.
44
* All rights reserved.
55
*
66
* The software in this package is published under the terms of the BSD
@@ -1915,12 +1915,13 @@ public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWrite
19151915
public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer, final String rootNodeName,
19161916
final DataHolder dataHolder)
19171917
throws IOException {
1918+
final DataHolder context = dataHolder != null ? dataHolder : new MapBackedDataHolder();
19181919
final StatefulWriter statefulWriter = new StatefulWriter(writer);
19191920
statefulWriter.startNode(rootNodeName, null);
1920-
return new CustomObjectOutputStream(new CustomObjectOutputStream.StreamCallback() {
1921+
return new CustomObjectOutputStream(context, new CustomObjectOutputStream.StreamCallback() {
19211922
@Override
19221923
public void writeToStream(final Object object) {
1923-
marshal(object, statefulWriter, dataHolder);
1924+
marshal(object, statefulWriter, context);
19241925
}
19251926

19261927
@Override

xstream/src/java/com/thoughtworks/xstream/core/JVM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public int compare(final Object o1, final Object o2) {
187187
canParseISO8601TimeZoneInDateFormat = test;
188188
try {
189189
@SuppressWarnings("resource")
190-
final CustomObjectOutputStream stream = new CustomObjectOutputStream(null);
190+
final CustomObjectOutputStream stream = new CustomObjectOutputStream(null, null);
191191
test = stream != null;
192192
} catch (final RuntimeException e) {
193193
test = false;

xstream/src/java/com/thoughtworks/xstream/core/util/CustomObjectOutputStream.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2004, 2005 Joe Walnes.
3-
* Copyright (C) 2006, 2007, 2014, 2016 XStream Committers.
3+
* Copyright (C) 2006, 2007, 2014, 2016, 2020 XStream Committers.
44
* All rights reserved.
55
*
66
* The software in this package is published under the terms of the BSD
@@ -34,8 +34,7 @@ public static synchronized CustomObjectOutputStream getInstance(final DataHolder
3434
try {
3535
CustomObjectOutputStream result = (CustomObjectOutputStream)whereFrom.get(DATA_HOLDER_KEY);
3636
if (result == null) {
37-
result = new CustomObjectOutputStream(callback);
38-
whereFrom.put(DATA_HOLDER_KEY, result);
37+
result = new CustomObjectOutputStream(whereFrom, callback);
3938
} else {
4039
result.pushCallback(callback);
4140
}
@@ -66,8 +65,12 @@ public static interface StreamCallback {
6665
* @see #getInstance(com.thoughtworks.xstream.converters.DataHolder,
6766
* com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback)
6867
*/
69-
public CustomObjectOutputStream(final StreamCallback callback) throws IOException, SecurityException {
68+
public CustomObjectOutputStream(final DataHolder dataHolder, final StreamCallback callback)
69+
throws IOException, SecurityException {
7070
callbacks.push(callback);
71+
if (dataHolder != null) {
72+
dataHolder.put(DATA_HOLDER_KEY, this);
73+
}
7174
}
7275

7376
/**

0 commit comments

Comments
 (0)