浏览代码

Added errorStream null check in HttpClient (used for testing purpose)

Luca Cavanna 12 年之前
父节点
当前提交
f9f664bc3b
共有 1 个文件被更改,包括 6 次插入4 次删除
  1. 6 4
      src/test/java/org/elasticsearch/test/integration/rest/helper/HttpClient.java

+ 6 - 4
src/test/java/org/elasticsearch/test/integration/rest/helper/HttpClient.java

@@ -105,10 +105,12 @@ public class HttpClient {
         } catch (IOException e) {
         } catch (IOException e) {
             InputStream errStream = urlConnection.getErrorStream();
             InputStream errStream = urlConnection.getErrorStream();
             String body = null;
             String body = null;
-            try {
-                body = Streams.copyToString(new InputStreamReader(errStream, Charsets.UTF_8));
-            } catch (IOException e1) {
-                throw new ElasticSearchException("problem reading error stream", e1);
+            if (errStream != null) {
+                try {
+                    body = Streams.copyToString(new InputStreamReader(errStream, Charsets.UTF_8));
+                } catch (IOException e1) {
+                    throw new ElasticSearchException("problem reading error stream", e1);
+                }
             }
             }
             return new HttpClientResponse(body, errorCode, respHeaders, e);
             return new HttpClientResponse(body, errorCode, respHeaders, e);
         } finally {
         } finally {