From 6eb4cd276c9cb8b6227c8ecb695106e2c226a2c3 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 13 Mar 2018 16:00:41 +0900 Subject: [PATCH] AmazonS3: Refactor error method to avoid 'should be managed by try-with-resource' warning Change-Id: I205fc1c77777870b0a036e52fa9954de5d9f60b5 Signed-off-by: David Pursehouse --- .../src/org/eclipse/jgit/transport/AmazonS3.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index 71e3d16c47..740a284302 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -524,12 +524,11 @@ public class AmazonS3 { JGitText.get().amazonS3ActionFailed, action, key, Integer.valueOf(HttpSupport.response(c)), c.getResponseMessage())); - final InputStream errorStream = c.getErrorStream(); - if (errorStream == null) { + if (c.getErrorStream() == null) { return err; } - try { + try (InputStream errorStream = c.getErrorStream()) { final ByteArrayOutputStream b = new ByteArrayOutputStream(); byte[] buf = new byte[2048]; for (;;) { @@ -545,8 +544,6 @@ public class AmazonS3 { if (buf.length > 0) { err.initCause(new IOException("\n" + new String(buf))); //$NON-NLS-1$ } - } finally { - errorStream.close(); } return err; } -- 2.39.5