ArrayIndexOutOfBoundsException when using XStream
Asked Answered
I

1

6

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.

Inversion answered 25/9, 2015 at 5:54 Comment(6)
I would check p object contents -> should be something wrong on one of them. Or maybe xstream has an issueRelentless
The contents of p (products) are actually subclasses of Product. Could that be a potential issue?Inversion
Might be a bug that was fixed in 1.4.6: x-stream.github.io/jira/746Abbreviation
The issue has nothing to do with your foreach loop. Maybe change the title and question?Industrialize
@Abbreviation Thank you, I updated the version of my file and that appears to have fixed the issue. I didn't even think about checking for a bug in xstream.Inversion
@Inversion Then you should probably answer your own question and accept that answer. It could be useful that a certain version of XStream has a bug.Ontiveros
I
8

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.

Inversion answered 25/9, 2015 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.