Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325376 - MOXy: Null pointer in XMLObjectReferenceMapping when target xpath is invalid
Summary: MOXy: Null pointer in XMLObjectReferenceMapping when target xpath is invalid
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-15 12:48 EDT by David McCann CLA
Modified: 2022-06-09 10:19 EDT (History)
0 users

See Also:


Attachments
Proposed fix. (6.50 KB, patch)
2010-09-23 16:01 EDT, David McCann CLA
no flags Details | Diff
Supporting test cases (7.00 KB, patch)
2010-09-23 16:01 EDT, David McCann CLA
no flags Details | Diff
Annotation test case mods (1.07 KB, patch)
2010-09-23 16:20 EDT, David McCann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David McCann CLA 2010-09-15 12:48:24 EDT
If the target xpath in an object reference mapping is invalid, the following exception is thrown:

-------------------------------------------------------------------------------
javax.xml.bind.UnmarshalException
 - with linked exception:
[java.lang.NullPointerException]
	at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:129)
	at org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmljoinnode.XmlJoinNodeTestCases.testUnmarshal(XmlJoinNodeTestCases.java:133)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at junit.framework.TestCase.runTest(TestCase.java:168)
	at junit.framework.TestCase.runBare(TestCase.java:134)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:124)
	at junit.framework.TestSuite.runTest(TestSuite.java:232)
	at junit.framework.TestSuite.run(TestSuite.java:227)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
	at org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping.buildReference(XMLObjectReferenceMapping.java:176)
	at org.eclipse.persistence.internal.oxm.XMLObjectReferenceMappingNodeValue.attribute(XMLObjectReferenceMappingNodeValue.java:92)
	at org.eclipse.persistence.oxm.record.UnmarshalRecord.startElement(UnmarshalRecord.java:720)
	at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parseEvent(XMLStreamReaderReader.java:104)
	at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:79)
	at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:69)
	at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:650)
	at org.eclipse.persistence.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:598)
	at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:438)
	at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:126)
	... 20 more

-------------------------------------------------------------------------------

The offending lines of code start at 170 of XMLObjectReferenceMapping:

XMLField tgtFld = (XMLField)
     getSourceToTargetKeyFieldAssociations().get(xmlField);

int idx = pkFieldNames.indexOf(tgtFld.getXPath());

Object value = 
   session.getDatasourcePlatform().getConversionManager().
   convertObject(object, 
   referenceDescriptor.getTypedField(tgtFld).getType());


Since tgtFld is null, the following call causes a null pointer:

    referenceDescriptor.getTypedField(tgtFld).getType()

We should be checking the target xpaths in the initialize method of XMLObjectReferenceMapping, and presumably XMLCollectionReferenceMapping as well (unless the ORM init suffices due to inheritance).

One thing to consider when validating target xpaths is that in the case of an Embeddable Key Class, the reference descriptor will not have a field for the given xpath, but the embeddable key class will.
Comment 1 David McCann CLA 2010-09-23 15:20:51 EDT
This work will be broken into two parts:

1) Validate that for each referenced-xml-path the target typeinfo has an XmlID/XmlKey property with a matching XPath.

2) Open an Enhancement Request for EmbeddedId class support.  This is required, as we will need access to the embedded id class' typeinfo from the target type info.
Comment 2 David McCann CLA 2010-09-23 16:01:04 EDT
Created attachment 179480 [details]
Proposed fix.
Comment 3 David McCann CLA 2010-09-23 16:01:18 EDT
Created attachment 179481 [details]
Supporting test cases
Comment 4 David McCann CLA 2010-09-23 16:20:18 EDT
Created attachment 179485 [details]
Annotation test case mods
Comment 5 David McCann CLA 2010-09-23 16:24:31 EDT
Reviewed by:  matt.macivor@oracle.com
Tests:  jaxb/externalizedmetadata/xmljoinnode/XmlJoinNodeTestCases; all unit tests pass as expected
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:19:41 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink