Search code examples
javajaxbmoxy

MOXy - StackOverflowError when bootstrapping JAXBContext with a self-containing class


I'm trying to use the EclipseLink MOXy JAXB implementation to umarshal some XML data. I have the following annotated class, which has a member of its own type:

package stackoverflow.q19191209;

import javax.xml.bind.annotation.*;

@XmlRootElement(name="Item")
public class Item
{
    @XmlAttribute(name="name")
    @XmlID
    private String m_name;

    @XmlAttribute(name="parent")
    @XmlIDREF 
    private Item m_parent;
}

This class is listed in jaxb.index. When I attempt to bootstrap my JAXBContext:

JAXBContext context = JAXBContext.newInstance("stackoverflow.q19191209");       

it hangs for a second, and then gives me a StackOverflowError:

Exception in thread "main" java.lang.StackOverflowError
    at java.util.HashMap$ValueIterator.<init>(HashMap.java:820)
    at java.util.HashMap$ValueIterator.<init>(HashMap.java:820)
    at java.util.HashMap.newValueIterator(HashMap.java:843)
    at java.util.HashMap$Values.iterator(HashMap.java:910)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.hasTextMapping(AnnotationsProcessor.java:3998)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.hasTextMapping(AnnotationsProcessor.java:4003)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.hasTextMapping(AnnotationsProcessor.java:4003)
...

This does not happen when I use the default JAXB provider - it unmarshals correctly, and all relationships are correctly established. Is this a MOXy bug?

I've tried JDK 1.6.0_25 and JDK 1.7.0_21, and MOXy versions 2.5.0, 2.5.1, and 2.6.0 - same results.

Thanks! Steve


Solution

  • Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

    UPDATE

    A fix for this issue has been checked into EclipseLink 2.5.2 and 2.6.0. You can download a nightly build with this fix starting October 11, 2013 from the following link:


    ORIGINAL ANSWER

    I have been able to reproduce the issue that you are seeing. You can use the following link to track our progress on this issue: