users@jersey.java.net

[Jersey] Re: NPE with Jersey 1 + Jackson 2 JAX-RS JSON provider

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Mon, 8 Jul 2013 13:46:06 +0200

This seems (partly) like a bug in Jersey CommitingOutputStream implementation. It would be probably better to fail earlier to make the real issue more easily spotted.

Can you please file a bug against Jersey 1.x (https://jersey.java.net/contribute.html)?

Thanks,
Marek

On Jun 20, 2013, at 1:13 PM, Marko Asplund <marko.asplund_at_gmail.com> wrote:

> Hi,
>
> I'm trying to use Jersey 1.17 client with Jackson 2.2 JAX-RS JSON provider.
> This seems to be working ok mostly, but if I try to do a HTTP put
> operation with JSON data to a target that doesn't respond, I get a
> NPE. This can make application issues difficult to troubleshoot
> sometimes.
> Jersey 1 JAX-RS JSON provider throws a java.net.ConnectException instead.
>
> Is Jersey 1 and Jackson 2 (incl. JAX-RS JSON) a "safe" combination to
> use in general?
>
> Here's my code:
>
> ClientConfig cc = new DefaultClientConfig();
> cc.getFeatures().put("com.sun.jersey.api.json.POJOMappingFeature",
> Boolean.TRUE); // NPE thrown with or without this
> Client c = Client.create(cc);
> WebResource w = c.resource("http://127.0.0.1:7483/foo/bar");
> w.type(MediaType.APPLICATION_JSON_TYPE).put(new SomeData("abc"));
>
> And the exception:
>
> Exception in thread "main"
> com.sun.jersey.api.client.ClientHandlerException:
> java.lang.NullPointerException
> at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
> at com.sun.jersey.api.client.Client.handle(Client.java:648)
> at com.sun.jersey.api.client.WebResource.voidHandle(WebResource.java:704)
> at com.sun.jersey.api.client.WebResource.access$400(WebResource.java:74)
> at com.sun.jersey.api.client.WebResource$Builder.put(WebResource.java:522)
> at fi.markoa.proto.jersey1.JerseyPut.main(JerseyPut.java:22)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
> Caused by: java.lang.NullPointerException
> at com.sun.jersey.api.client.CommittingOutputStream.flush(CommittingOutputStream.java:101)
> at com.fasterxml.jackson.core.json.UTF8JsonGenerator.close(UTF8JsonGenerator.java:1086)
> at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:463)
> at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300)
> at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:213)
> at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
> ... 10 more
>
> marko