Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayIndexOutOfBoundsException when using XStream

Tags:

java

xml

xstream

I'm not sure how this is even possible, but the program I am running is giving me an odd error. I am getting an ArrayIndexOutOfBoundsException: -1 on a for each loop. The entire error is below:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at com.thoughtworks.xstream.core.util.OrderRetainingMap.entrySet(OrderRetainingMap.java:77)
at java.util.HashMap.putMapEntries(HashMap.java:511)
at java.util.HashMap.putAll(HashMap.java:784)
at com.thoughtworks.xstream.core.util.OrderRetainingMap.<init>(OrderRetainingMap.java:36)
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(FieldDictionary.java:135)
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldsFor(FieldDictionary.java:76)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:126)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:81)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:895)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:884)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:857)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:844)
at unl.cse.assignments.DataConverter.output(DataConverter.java:210)
at unl.cse.assignments.DataConverter.main(DataConverter.java:121)

Line 210 is the pw.print line:

for(Product p : products)
    {
        if(AwardTicket.class.isInstance(p)){
            xstream.alias("awardTicket", AwardTicket.class);
            pw.print(xstream.toXML(p) + "\n");
        }
}

(Line 121 just calls on the output)

I've been investigating this error for a long time and I can't figure out the cause of it. I assumed there was something wrong with the xstream, but I tried it with other outputs.

like image 754
Tanner Avatar asked Sep 25 '15 05:09

Tanner


1 Answers

As Andreas pointed out, this is actually a bug in XStream that was fixed in version 1.4.6. The latest version of XStream can be downloaded here.

like image 112
Tanner Avatar answered Nov 03 '22 11:11

Tanner