]> source.dussan.org Git - jgit.git/commitdiff
AmazonS3: Refactor error method to avoid 'should be managed by try-with-resource... 92/119292/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 13 Mar 2018 07:00:41 +0000 (16:00 +0900)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 13 Mar 2018 21:21:36 +0000 (22:21 +0100)
Change-Id: I205fc1c77777870b0a036e52fa9954de5d9f60b5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java

index 71e3d16c4794eb23e459500f3eb6a478cf9a709e..740a284302997a267c10611281ff843fab347796 100644 (file)
@@ -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;
        }