users@jaxb.java.net

Re: NullPointerException

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Sun, 18 Dec 2011 09:14:38 +0100

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.

-W

On 16/12/2011, Alex Vb <i8c.alex_at_gmail.com> wrote:
> 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...?
>