metro-jax-ws
metro-jax-ws copied to clipboard
xsi:nil on root element triggers NPE
I reported this originally on the jaxb mailing list (http://java.net/projects/jaxb/lists/users/archive/2011-12/message/16)::)
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"/>
Someone on the list replied:
Although the NPE occurs in JAXB code, I'm not sure that the fix should be made as proposed. It's possible that the JAX-WS unmarshalling code has a flaw here, as it should not proceed on a repsonse that's null – provided I've understood this correctly and it is the pointer to what would normally be the root element of the payload that is intended to be nillable.
Whether this is in line with the JAX-WS specification I'm not prepared to comment upon, but this isn't relevant: defensive coding should take care of this on first encounter of the null value and not try and continue as if it were the regular case.
I reported this on the jaxws mailing list a while ago as well: http://java.net/projects/jax-ws-commons/lists/users/archive/2011-12/message/0 and http://java.net/projects/jax-ws/lists/users/archive/2011-12/message/4 but there was no response.
Back when I first reported it, I "fixed" it locally by patching jaxb to check for a null value before invoking the offending code and had more or less forgotten about it until now (hence the rather late bug report)
Source: https://github.com/javaee/metro-jax-ws/issues/1065 Author: glassfishrobot