I have created a JAX-WS client and am trying to execute a webservice that
has a nillable output. As long as the output isn't nil, everything works
just fine, however if the webservice simply returns the root element with
xsi:nil="true", I get the following exception:
Caused by: java.lang.NullPointerException
at <MyClass>$JaxbAccessorF_log.get(FieldAccessor_Ref.java:56)
at
com.sun.xml.bind.v2.runtime.property.SingleReferenceNodeProperty$1.get(SingleReferenceNodeProperty.java:145)
at
com.sun.xml.bind.v2.runtime.reflect.Accessor.getUnadapted(Accessor.java:147)
at
com.sun.xml.bind.v2.runtime.JAXBContextImpl$6.get(JAXBContextImpl.java:966)
at
com.sun.xml.ws.client.sei.ResponseBuilder$DocLit$PartBuilder.readResponse(ResponseBuilder.java:603)
at
com.sun.xml.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:559)
at
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:125)
at
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)
at $Proxy43.current(Unknown Source)
The XML amounts to:
<root:currentResponse xsi:nil="true"/>
The JAXB version that I'm using is "2.1.6" but a very small test indicates
that the error is reproducible with "2.2.4".
After some soul searching and code browsing I found the offending line in
com.sun.xml.bind.v2.runtime.reflect.opt.FieldAccessor_Ref, the get(Object
bean) simply does:
return ((Bean)bean).f_ref;
However in this scenario the bean is "null". Updating it to something like
return bean == null ? null : ((Bean)bean).f_ref;
fixes the issue and doesn't seem to break other stuff.
So my question is: is this an actual bug or do I have to configure
something to make this work or is it somehow a problem in JAX-WS or...?