Details
-
Type: Bug
-
Status: Closed
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: 1.1.3
-
Component/s: None
-
Labels:None
-
JDK version and platform:JDK 1.5
Description
Hi
I am new to XStream, so it may not be a bug.
If value is not specified, then XStream crashes during XML parsing/object creation.
Here is the Exception stack trace -
Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: For input string: ""
---- Debugging information ----
required-type : java.lang.Integer
cause-message : For input string: ""
class : xStreamTest
message : For input string: ""
line number : 1
path : /xStreamTest/num
cause-exception : java.lang.NumberFormatException
-------------------------------
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:45)
at com.thoughtworks.xstream.core.ReferenceByXPathUnmarshaller.convertAnother(ReferenceByXPathUnmarshaller.java:39)
at com.thoughtworks.xstream.converters.reflection.ReflectionConverter.unmarshal(ReflectionConverter.java:103)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:38)
at com.thoughtworks.xstream.core.ReferenceByXPathUnmarshaller.convertAnother(ReferenceByXPathUnmarshaller.java:39)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:99)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:12)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:552)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:540)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:490)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:483)
at xStreamTest.main(xStreamTest.java:63)
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at java.lang.Integer.decode(Unknown Source)
at com.thoughtworks.xstream.converters.basic.IntConverter.fromString(IntConverter.java:16)
at com.thoughtworks.xstream.converters.basic.AbstractBasicConverter.unmarshal(AbstractBasicConverter.java:33)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:38)
... 11 more
and Here is the code -
import com.thoughtworks.xstream.XStream;
public class xStreamTest {
private java.lang.String[] address1;
private String[] address2;
private int num;
/**
- @return Returns the num.
*/
public int getNum() { return num; }/**
- @param num The num to set.
*/
public void setNum(int num) { this.num = num; }/**
- @return Returns the address1.
*/
public java.lang.String[] getAddress1() { return address1; }/**
- @param address1 The address1 to set.
*/
public void setAddress1(java.lang.String[] address1) { this.address1 = address1; }/**
- @return Returns the address2.
*/
public String[] getAddress2() { return address2; }/**
- @param address2 The address2 to set.
*/
public void setAddress2(String[] address2) { this.address2 = address2; }
public static void main(String[] args) throws Exception
{
XStream xStream = new XStream();
xStreamTest test = new xStreamTest();
String[] addressTemp1 =
;
String[] addressTemp2 =
;
test.setAddress1(addressTemp1);
test.setAddress2(addressTemp2);
String xmlString = xStream.toXML(test);
//System.out.println(xmlString);
xmlString = "<xStreamTest><address1><string>Montgomery</string><string>Howard</string><string>Baltimore</string>" +
"</address1><address2><string>Fairfax</string><string>Loudoun</string><string>DC</string>" +
"</address2><num></num></xStreamTest>";
xStreamTest test2 = (xStreamTest) xStream.fromXML(xmlString);
String[] addressTemp3 = test2.getAddress1();
System.out.println(addressTemp3[0]);
}
}
This is by design. The provided value is no number. Please ask questions like this on the mailing list first.