Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: None
-
Fix Version/s: 1.1.3
-
Component/s: None
-
Labels:None
-
JDK version and platform:jdk 1.5_03 on Windows
Description
I'm new to XStream (tried to use it with mule) and while doing my first experiment I of course stepped on a mine. Looky:
XStream xstream = new XStream();
Object o = Arrays.asList(new Integer[]
);
String xml = xstream.toXML(o);
log.info("xml: " + xml);
Object newObject = xstream.fromXML(xml);
log.info("new object: " + newObject);
gives:
[05-10 22:27:10] INFO XStreamTest: xml: <java.util.Arrays-ArrayList>
<a class="int-array">
<int>42</int>
</a>
</java.util.Arrays-ArrayList>
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.valueOf(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuffer.append(Unknown Source)
at h2o.playground.XStreamTest.main(XStreamTest.java:24)
It seems XStream has problems properly recognizing the static inner class in java.util.Arrays which is a special kind of ArrayList that doesn't copy the array it contains.
From reading the feature list I'm not sure if this is a bug in XStream; if I need to configure something in a special way or this is just a special case that does not work, please let me know and disregard this bug.
Thanks,
Holger
Some more info. It turns out that the object is re-created properly, but for some reason toString() fails. I suspected that it's related to my using eclipse 3.0.2 in 1.4-mode with jdk 1.5 but that doesn't seem to be the case; it happens when compiled from the command line, too.
Interestingly enough, the following:
List newObject = (List)xstream.fromXML(xml);
log.info("new.size: " + newObject.size());
log.info("new(0):" + newObject.get(0));
gives:
INFO: new.size: 1
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at h2o.playground.XStreamTest.main(XStreamTest.java:28)
so it seems the problen is the List's internal array. It gets better though:
Object first = newObject.get(0);
log.info("first.class:" + first.getClass());
gives the best fireworks:
INFO: new.size: 1
#
#
#
#
#
#
..which indicates that the internal array is not null and contains something really bogus. I didn't investigate the stack trace further