Friday, July 19, 2013

JAXB Marshaller no threadsafe - Error

I got this error...

java.lang.ArrayIndexOutOfBoundsException: -1
at com.sun.xml.bind.v2.util.CollisionCheckStack.pushNocheck(CollisionCheckStack.java:132)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:491)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:116)

at ....sci.XmlUtil.convertToXml(XmlUtil.java:52)

or this one:

java.lang.NullPointerException
at com.sun.xml.internal.bind.v2.runtime.Coordinator.popCoordinator(Coordinator.java:150)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.close(XMLSerializer.java:847)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:116)
at .....XmlUtil.convertToXml(XmlUtil.java:52)

Cause:

Our XML class was sharing Marshaller and Unmarshaller instances among several threads.

Solution:

Create a Marshaller and Unmarshaller per request, as described in this Link


1 comment: