briandilley/jsonrpc4j

NPE on using result of getErrorStream()

Closed this issue · 6 comments

try (InputStream answer = getStream(connection.getErrorStream(), useGzip)) {

This line throws NPE because java.net.HttpURLConnection.getErrorStream() returns null.

Will take a look at this tonight.

Hi @mrezin,

Can you please provide some reproduction steps for this issue?

It happens when client receives timeout exception.
private int readTimeoutMillis = 60 * 1000 * 2;

Steps to reproduce:

  1. Establish connection to the server
  2. Suspend corresponding thread on the server
  3. Invoke method and wait for the timeout (java.io.IOException: Connection timed out)
  4. Catch (IOException) block calls getErrorStream() and receives null which leads to NPE

Got it, thanks. Should have a PR out later this evening.

@mrezin PR up. Thanks for finding this. If you would be kind enough to pitch in reviewing the PR I'd be very grateful.

Sure, I'd be happy to review the PR