Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NullPointerException from moxy due to corrupted CycleDetectionStack
NullPointerException from moxy due to corrupted CycleDetectionStack [message #1108672] Sat, 14 September 2013 06:40 Go to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
I have one object A with a property whose type can only be decided at runtime. The only information I know is that the property can be serialized using JAXB.
So I give this property XmlAnyElement with a XmlAdapter.

<xml-any-element java-attribute="Format">
               <xml-java-type-adapter value="com.flexdms.flexims.typedb.eclipselink.ObjectAdapter"/>
            </xml-any-element>



public class ObjectAdapter extends XmlAdapter<Element, Object>
{
	/*
	 * 
	 * Class<?> relatedClasses[];
	 * 
	 * 
	 * 
	 * public ObjectTransfomer(List<Class<?>> relatedClasses) { super();
	 * this.relatedClasses =relatedClasses.toArray(new Class<?>[0]); }
	 */

	// how to do json
	@Override
	public Element marshal(Object arg0) throws Exception
	{
		if (arg0==null)
		{
			return null;
		}
		Class<?> cls = arg0.getClass();
		JAXBContext context = JAXBContext.newInstance(cls);
		Marshaller marshaller = context.createMarshaller();

		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		dbf.setNamespaceAware(true);
		DocumentBuilder db = dbf.newDocumentBuilder();
		Document doc = db.newDocument();
		
		Element root = doc.createElement("object");
		root.setAttribute("cls", cls.getName());
		doc.appendChild(root);
		marshaller.setProperty("jaxb.fragment", true);
		marshaller.marshal(arg0, root);
		
		root=(Element) doc.removeChild(root);

		return root;
	}
}


Object A also has other relation and properties. When I marshal a single A, there is no problem. When I marshal multiple As, I got this exception
Caused by: java.lang.NullPointerException
	at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshal(XMLCompositeObjectMappingNodeValue.java:144)
	at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102)
	at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59)
	at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:393)
	at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:238)
	at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118)
	at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1)
	at org.eclipse.persistence.internal.oxm.XMLAnyCollectionMappingNodeValue.marshalSingleValue(XMLAnyCollectionMappingNodeValue.java:432)
	at org.eclipse.persistence.internal.oxm.XMLAnyCollectionMappingNodeValue.marshal(XMLAnyCollectionMappingNodeValue.java:147)
	at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:149)
	at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102)
	at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59)
	at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:393)
	at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:238)
	at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118)
	at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1)
	at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:743)
	at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:1124)
	at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:1027)
	at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:604)
	... 38 more



I traced the code to org.eclipse.persistence.internal.oxm.XMLMarshaller
line 813:NodeRecord contentHandlerRecord = new NodeRecord(node);

When the Marshaller inside of my Adapter reaches this line, the returned NodeRecord has a cycleDetectionStack with two items at stack, and currentIndex=0. The two items in the stack is from top marshaller. I just wonder how my inner/completely different marshaller can have some state from parent marshaller. Does moxy marshaller keep some information which is thread-local that can be shared by all marshaller from different JAXBContext?

I am trying to produce a simple test case, but so far I can not find a simple case to show this.

Does anyone have any suggestion on this one?
Re: NullPointerException from moxy due to corrupted CycleDetectionStack [message #1108683 is a reply to message #1108672] Sat, 14 September 2013 07:02 Go to previous messageGo to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
I can reproduce this with some simple code. So I filed a bug:https://bugs.eclipse.org/bugs/show_bug.cgi?id=417246.
Re: NullPointerException from moxy due to corrupted CycleDetectionStack [message #1110382 is a reply to message #1108683] Mon, 16 September 2013 20:25 Go to previous message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi Jason,


Thank you very much for providing the test case, we are investigating what the issue is.

-Blaise
Previous Topic:Using preInsert, preUpdate, prePersist, etc. to selectively prevent inserts and updates
Next Topic:Cascade.remove performance suggestions
Goto Forum:
  


Current Time: Fri Mar 29 09:15:57 GMT 2024

Powered by FUDForum. Page generated in 0.03381 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top