Details
Description
The attached program recreates an exception when reading back in the field XStreamBug.Bug._underscore field.
Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: null
---- Debugging information ----
message : null
cause-exception : java.lang.NumberFormatException
cause-message : null
class : XStreamBug$Bug
required-type : XStreamBug$Bug
line number : 1
-------------------------------
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:63)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
at com.thoughtworks.xstream.core.ReferenceByIdMarshallingStrategy.unmarshal(ReferenceByIdMarshallingStrategy.java:14)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:832)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:819)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:767)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:759)
at XStreamBug.main(XStreamBug.java:14)
Caused by: java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:372)
at java.lang.Long.valueOf(Long.java:518)
at com.thoughtworks.xstream.converters.basic.LongConverter.fromString(LongConverter.java:16)
at com.thoughtworks.xstream.converters.SingleValueConverterWrapper.fromString(SingleValueConverterWrapper.java:31)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:142)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:121)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
... 9 more
The line "xs.useAttributeFor(long.class)" is the key to recreating this exception. When left out, it works fine. Stepping through the code shows that the attribute name doesn't get escaped before asking the reader for the attribute. For example, in XppReader, the getAttribute(String name) method should probably be something like the following:
public String getAttribute(String name)
{ return parser.getAttributeValue(null, replacer.escapeName(name)); }Essentially, any field that has an underscore that is written out as an attribute doesn't get deserialized properly without some type of exception.
PS. This fails in 1.2.1 as well.