users@jersey.java.net

Re: [Jersey] NPE at AbstractMessageReaderWriterProvider.readFromAsString()

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 10 Dec 2008 10:47:32 +0100

HI Gili,

Thanks for reporting this.

I think the solution should be not to set the input stream to null but
to leave it as is and then let any exception flow through or return of
a null value if all the bytes in the input stream are consumed. That
way it would be possible to call it more than once if supported for
deserialization of certain java types that consume only as much as
they require. We should JavaDoc the restrictions on the invocation of
getEntity.

Paul.

On Dec 10, 2008, at 6:41 AM, Gili wrote:

>
> I figured it out. It looks like I can invoke
> ClientResponse.getEntity(String.class) once, but if I invoke it twice
> consecutively this exception is thrown. This is caused by the fact
> that
> URLConnectionClientHandler.java line 160 sets "in" (the InputStream)
> to
> null. I posted this bug report:
> https://jersey.dev.java.net/issues/show_bug.cgi?id=159
>
> I pointed out one possible fix though I will be the first to admit
> that it
> is a little hairy. Hopefully you will find a cleaner solution.
>
> Thank you,
> Gili
>
>
> Gili wrote:
>>
>> Hi Paul,
>>
>> I get this exception in jersey-client when I invoke
>> ClientResponse.getEntity(String.class):
>>
>> java.lang.NullPointerException
>> at java.io.Reader.<init>(Reader.java:61)
>> at java.io.InputStreamReader.<init>(InputStreamReader.java:96)
>> at
>> com
>> .sun
>> .jersey
>> .core
>> .provider
>> .AbstractMessageReaderWriterProvider
>> .readFromAsString(AbstractMessageReaderWriterProvider.java:85)
>> at
>> com
>> .sun
>> .jersey
>> .core
>> .impl.provider.entity.StringProvider.readFrom(StringProvider.java:70)
>> at
>> com
>> .sun
>> .jersey
>> .core
>> .impl.provider.entity.StringProvider.readFrom(StringProvider.java:55)
>> at
>> com.sun.jersey.client.impl.urlconnection.URLConnectionClientHandler
>> $URLConnectionResponse.getEntity(URLConnectionClientHandler.java:156)
>> at
>> com.sun.jersey.client.impl.urlconnection.URLConnectionClientHandler
>> $URLConnectionResponse.getEntity(URLConnectionClientHandler.java:138)
>> at
>> adcaster.shared.persistence.Resources
>> $IOExceptionBuilder.cause(Resources.java:192)
>>
>>
>> Please confirm.
>>
>> Thanks,
>> Gili
>>
>
> --
> View this message in context: http://n2.nabble.com/NPE-at-AbstractMessageReaderWriterProvider.readFromAsString%28%29-tp1636314p1637389.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>