XStream

Unmarshaling fields with underscores results in exception when fields serialized as attributes instead of tags.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.3
  • Fix Version/s: 1.3.1
  • Component/s: IO
  • Labels:
    None
  • JDK version and platform:
    Sun 1.6.0_04 for Windows

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.

Activity

Hide
Rob Beazizo added a comment -

PS. This fails in 1.2.1 as well.

Show
Rob Beazizo added a comment - PS. This fails in 1.2.1 as well.
Hide
Joerg Schaible added a comment -

Resolved in head revision.

Show
Joerg Schaible added a comment - Resolved in head revision.
Hide
Joerg Schaible added a comment -

Set correct fix version.

Show
Joerg Schaible added a comment - Set correct fix version.
Hide
Joerg Schaible added a comment -

Fixed for upcoming release.

Show
Joerg Schaible added a comment - Fixed for upcoming release.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: