[FLINK-9580][rest] Close streams in RestClient#readRawResponse

This closes #6166.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/1bdc7194
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/1bdc7194
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/1bdc7194

Branch: refs/heads/release-1.5
Commit: 1bdc7194dff23b3ce3181c687be53f8a66a31bfe
Parents: d8ad69f
Author: yanghua <[email protected]>
Authored: Thu Jun 14 16:16:20 2018 +0800
Committer: zentol <[email protected]>
Committed: Wed Jun 27 22:01:27 2018 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/flink/runtime/rest/RestClient.java    | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/1bdc7194/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
----------------------------------------------------------------------
diff --git 
a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java 
b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
index ee0201c..c9da501 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
@@ -406,16 +406,14 @@ public class RestClient {
                        ByteBuf content = msg.content();
 
                        JsonNode rawResponse;
-                       try {
-                               InputStream in = new 
ByteBufInputStream(content);
+                       try (InputStream in = new ByteBufInputStream(content)) {
                                rawResponse = objectMapper.readTree(in);
                                LOG.debug("Received response {}.", rawResponse);
                        } catch (JsonParseException je) {
                                LOG.error("Response was not valid JSON.", je);
                                // let's see if it was a plain-text message 
instead
                                content.readerIndex(0);
-                               try {
-                                       ByteBufInputStream in = new 
ByteBufInputStream(content);
+                               try (ByteBufInputStream in = new 
ByteBufInputStream(content)) {
                                        byte[] data = new byte[in.available()];
                                        in.readFully(data);
                                        String message = new String(data);

Reply via email to