From 0db2005de3c2ff245fddf7599fbdd7ce0a9a7b6d Mon Sep 17 00:00:00 2001 From: Tang HuaiZhe Date: Sat, 13 Apr 2019 15:37:51 +0800 Subject: [PATCH] Fix #4915 nullPointerException caused by realConnection is null --- .../java/okhttp3/internal/http1/Http1ExchangeCodec.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/okhttp/src/main/java/okhttp3/internal/http1/Http1ExchangeCodec.java b/okhttp/src/main/java/okhttp3/internal/http1/Http1ExchangeCodec.java index 586faba6c..a5c34cfa0 100644 --- a/okhttp/src/main/java/okhttp3/internal/http1/Http1ExchangeCodec.java +++ b/okhttp/src/main/java/okhttp3/internal/http1/Http1ExchangeCodec.java @@ -229,8 +229,12 @@ public final class Http1ExchangeCodec implements ExchangeCodec { return responseBuilder; } catch (EOFException e) { // Provide more context if the server ends the stream before sending a response. + String address = "unknown"; + if (realConnection != null) { + address = realConnection.route().address().url().redact(); + } throw new IOException("unexpected end of stream on " - + realConnection.route().address().url().redact(), e); + + address, e); } }