jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • XStream
  • XSTR-319

Crashes on integer conversion

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed 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 = {"Montgomery", "Howard", "Baltimore" };
String[] addressTemp2 = {"Fairfax","Loudoun", "DC"};

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]);
}
}

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
Hide
Permalink
Joerg Schaible added a comment - 12/Jun/06 4:53 PM

This is by design. The provided value is no number. Please ask questions like this on the mailing list first.

Show
Joerg Schaible added a comment - 12/Jun/06 4:53 PM This is by design. The provided value is no number. Please ask questions like this on the mailing list first.
Hide
Permalink
Jake added a comment - 05/Apr/11 7:39 AM

I realize the issue is closed, but I think RK has a valid point. Although "" is not a valid int value, Integer is an object which could be null. The IntConverter could easily support this. Could you think this over?

Show
Jake added a comment - 05/Apr/11 7:39 AM I realize the issue is closed, but I think RK has a valid point. Although "" is not a valid int value, Integer is an object which could be null. The IntConverter could easily support this. Could you think this over?

People

  • Assignee:
    Unassigned
    Reporter:
    RK
Vote (0)
Watch (1)

Dates

  • Created:
    12/Jun/06 3:35 PM
    Updated:
    05/Apr/11 7:39 AM
    Resolved:
    12/Jun/06 4:53 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.