Reputation: 15355
I have an error when unmarshaling XML to Java object with JAXB:
java.lang.NullPointerException
at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.parse(RuntimeBuiltinLeafInfoImpl.java:188)
at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.parse(RuntimeBuiltinLeafInfoImpl.java:186)
at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:230)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.LeafPropertyLoader.text(LeafPropertyLoader.java:50)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.text(UnmarshallingContext.java:483)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.text(InterningXmlVisitor.java:78)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.handleCharacters(StAXEventConnector.java:173)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(StAXEventConnector.java:127)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:392)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:368)
How can I find the cause?
some more details:
part of the xml that I am trying to parse is:
<member_resources>
<__field_location__>
<directive>
sun-sat
</directive>
<file>
null
</file>
<line>
0
</line>
</__field_location__>
<sun-sat>
00:00-24:00 tester2
</sun-sat>
<__field_location__>
<directive>
isLine
</directive>
<file>
null
</file>
<line>
0
</line>
</__field_location__>
<isLine>
true
</isLine>
</member_resources>
when stopping at the event that caused this I get:
next event <__field_location__>
next event <directive>
next event sun-sat
next event <file>
next event null
Upvotes: 1
Views: 802
Reputation: 8343
Add an exception breakpoint for NullPointerException
. When it's hit, explore a few levels higher in the call stack to find out the state of the local variables, you'll probably get a clue as to what is null.
Upvotes: 3
Reputation: 6890
A good approach is using source of JAXB
(its implementation) and a IDE for debugging.
Upvotes: 3
Reputation: 952
Well, a starting point could be setting a breakpoint at the call to the unmarshaler and check exactly which arguments it is being passed.
First thing I'd check is that what you're passing is actually xml, and that it is both well-formed and valid.
Upvotes: 1