From 3bf2e371228351e35bec1efd04ef89129fca0dc6 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Mon, 19 May 2014 22:14:20 -0400 Subject: [PATCH] Don't NPE after a redirect. We were releasing the connection (to the successor request) and later attempting to close the null connection. --- .../src/main/java/com/squareup/okhttp/Response.java | 13 ++++++------- .../squareup/okhttp/internal/http/HttpEngine.java | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/okhttp/src/main/java/com/squareup/okhttp/Response.java b/okhttp/src/main/java/com/squareup/okhttp/Response.java index 7da802686..276299222 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/Response.java +++ b/okhttp/src/main/java/com/squareup/okhttp/Response.java @@ -60,15 +60,14 @@ public final class Response { } /** - * The wire-level request that initiated this HTTP response. This is usually - * not the same request instance provided to the HTTP client: + * The wire-level request that initiated this HTTP response. This is not + * necessarily the same request issued by the application: * */ public Request request() { diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java b/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java index 27a6a25f1..5e1931655 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java +++ b/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java @@ -509,7 +509,7 @@ public final class HttpEngine { closeQuietly(responseBodyBytes); // Close the connection if it cannot be reused. - if (transport != null && !transport.canReuseConnection()) { + if (transport != null && connection != null && !transport.canReuseConnection()) { closeQuietly(connection.getSocket()); connection = null; return null;