Hi,
I'm using JAXB 2.1.2 release on JDK 1.5.0_10 and I have class StatusCode
annotated via JAXB 2.0 annotations. When unmarshalling from via Binder it
throws a NullPointerException.
After some research I found that cause of the problem is hashCode
implementation in that class - it uses internal field to calculate hasCode.
Looking at stack trace you will see: at com.sun.xml.bind.v2.runtime
.AssociationMap.addInner(AssociationMap.java:78)
At this point JAXB Binder.associateUnmarshall creates instance of StatusCode
class via default no-args constructors and tries to put it to the
AssociationMap but because all fields in the object are null - hashCode
fails with a NullPointerException (HashMap calls hashCode for the oject in
order to find bucket).
I think it's a bug - Binder uses HashMap for keeping DOM <-> Object
associations I think in this case it will make sense to use IdenityHashMap
(or similar structure) to keep these associations.
Stack trace:
com.comcast.xml.bind.XmlBindingException: java.lang.NullPointerException
at com.comcast.xml.bind.DefaultXmlBindingFactory.unmarshall(
DefaultXmlBindingFactory.java:99)
at com.comcast.saml.v20.protocol.StatusTest.testCreateStatusCode (
StatusTest.java:12)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run (TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(
JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(
TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(
RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (
RemoteTestRunner.java:196)
Caused by: java.lang.NullPointerException
at com.comcast.saml.v20.protocol.StatusCode.hashCode(StatusCode.java
:139)
at java.util.HashMap.put(HashMap.java:418)
at com.sun.xml.bind.v2.runtime.AssociationMap.addInner (
AssociationMap.java:78)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.recordInnerPeer
(UnmarshallingContext.java:1025)
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(
StructureLoader.java:147)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(
UnmarshallingContext.java:402)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement (
UnmarshallingContext.java:380)
at
com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(
InterningXmlVisitor.java:35)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement (
SAXConnector.java:101)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:224)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:107)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan (DOMScanner.java:85)
at com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(
BinderImpl.java:140)
at com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:111)
at com.comcast.xml.bind.DefaultXmlBindingFactory.unmarshall (
DefaultXmlBindingFactory.java:91)
... 19 more
Thanks,
Giedrius