Details
-
Type: Bug
-
Status: Closed
-
Resolution: Cannot Reproduce
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
JDK version and platform:Sun 1.4.2_13, 1.5.0_11, 1.6.0 on Linux
Description
Similar to XSTR-338 but trickier.
Happens when a field in the object to serialize is a Map, and the Map keys are static final objects (like in old-style enums). In this case currNode.clazz is null and
if (currNode == null || (Collection.class.isAssignableFrom(currNode.clazz) == false
&& currNode.clazz.isArray() == false)) {
throws a NPE.
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at com.thoughtworks.xstream.io.json.JsonHierarchicalStreamWriter.startNode(JsonHierarchicalStreamWriter.java:71)
at com.thoughtworks.xstream.io.WriterWrapper.startNode(WriterWrapper.java:22)
at com.thoughtworks.xstream.io.path.PathTrackingWriter.startNode(PathTrackingWriter.java:30)
at com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper.startNode(ExtendedHierarchicalStreamWriterHelper.java:6)
at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:51)
at com.thoughtworks.xstream.converters.collections.MapConverter.marshal(MapConverter.java:44)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:55)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.marshallField(AnnotationReflectionConverter.java:40)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:108)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:84)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:109)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:69)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:42)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:55)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:73)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.marshal(ReferenceByXPathMarshallingStrategy.java:34)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:751)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:740)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:721)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:711)
at XstreamJsonBug.test(XstreamJsonBug.java:32)
Actually it's much simpler than that, seems like a simple Map causes the same problem:
public class XSTR389Test extends TestCase {
public static class MapHolder {
private Map map = new HashMap();
public MapHolder()
{ map.put("a", "1"); }}
public void test()
{ XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); MapHolder mapHolder = new MapHolder(); String json = xstream.toXML(mapHolder); assertNotNull(json); }}
Please ignore my previous attachment (I don't have permission to delete it).