Details
Description
I can no longer serialise syncronised lists in 1.3.1.
The following code:
List<String> list = Collections.synchronizedList(new ArrayList<String>());
list.add("test");
XStream xstream = new XStream();
String xml = xstream.toXML(list);
System.out.println(xml);
causes the following Exception:
Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: Could not call java.util.Collections$SynchronizedList.writeObject() : Cannot reference implicit element
---- Debugging information ----
implicit-element : [test]
referencing-element : /java.util.Collections_-SynchronizedRandomAccessList/java.util.Collections_-SynchronizedCollection/default/mutex
-------------------------------
message : Could not call java.util.Collections$SynchronizedList.writeObject()
cause-exception : com.thoughtworks.xstream.core.AbstractReferenceMarshaller$ReferencedImplicitElementException
cause-message : Cannot reference implicit element
-------------------------------
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.callWriteObject(SerializationMethodInvoker.java:103)
at com.thoughtworks.xstream.converters.reflection.SerializableConverter.doMarshal(SerializableConverter.java:215)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:98)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:38)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:837)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:826)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:801)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:789)
at test.Test.main(Test.java:56)
Caused by: com.thoughtworks.xstream.core.AbstractReferenceMarshaller$ReferencedImplicitElementException: Cannot reference implicit element
---- Debugging information ----
implicit-element : [test]
referencing-element : /java.util.Collections_-SynchronizedRandomAccessList/java.util.Collections_-SynchronizedCollection/default/mutex
-------------------------------
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)
at com.thoughtworks.xstream.converters.reflection.SerializableConverter$1.defaultWriteObject(SerializableConverter.java:176)
at com.thoughtworks.xstream.core.util.CustomObjectOutputStream.defaultWriteObject(CustomObjectOutputStream.java:80)
at java.util.Collections$SynchronizedCollection.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.callWriteObject(SerializationMethodInvoker.java:99)
... 16 more
Output in 1.3:
<java.util.Collections_-SynchronizedRandomAccessList resolves-to="java.util.Collections$SynchronizedList" serialization="custom">
<java.util.Collections_-SynchronizedCollection>
<default>
<c class="list">
<string>test</string>
</c>
<mutex class="java.util.Collections$SynchronizedList" serialization="custom">
<java.util.Collections_-SynchronizedCollection>
<default>
<c class="list" reference="../../../../c"/>
<mutex class="java.util.Collections$SynchronizedList" reference="../../.."/>
</default>
</java.util.Collections_-SynchronizedCollection>
<java.util.Collections_-SynchronizedList>
<default>
<list reference="../../../../c"/>
</default>
</java.util.Collections_-SynchronizedList>
</mutex>
</default>
</java.util.Collections_-SynchronizedCollection>
<java.util.Collections_-SynchronizedList>
<default>
<list reference="../../../java.util.Collections_-SynchronizedCollection/default/c"/>
</default>
</java.util.Collections_-SynchronizedList>
</java.util.Collections_-SynchronizedRandomAccessList>