| Summary: | MOXy: Null pointer in XMLObjectReferenceMapping when target xpath is invalid | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | David McCann <david.mccann> | ||||||||
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> | ||||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | ||||||||||
| Version: | unspecified | ||||||||||
| Target Milestone: | --- | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Windows XP | ||||||||||
| Whiteboard: | |||||||||||
| Attachments: |
|
||||||||||
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. Created attachment 179480 [details]
Proposed fix.
Created attachment 179481 [details]
Supporting test cases
Created attachment 179485 [details]
Annotation test case mods
Reviewed by: matt.macivor@oracle.com Tests: jaxb/externalizedmetadata/xmljoinnode/XmlJoinNodeTestCases; all unit tests pass as expected The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
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.