]> source.dussan.org Git - jgit.git/commitdiff
TransportHttp: Refactor to use try-with-resource and suppress resource warning 37/119737/3
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 20 Mar 2018 02:37:30 +0000 (11:37 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Sun, 25 Mar 2018 08:49:43 +0000 (09:49 +0100)
Change-Id: I130269e7c5e46aea2152dea6b02539529208eea2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

index b300d55477e287cae1b5704584fd49fa3df76a26..87c328f45209ad50f332dc23494add2e280ca65d 100644 (file)
@@ -336,6 +336,22 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
                useSmartHttp = on;
        }
 
+       @SuppressWarnings("resource") // Closed by caller
+       private FetchConnection getConnection(HttpConnection c, InputStream in,
+                       String service) throws IOException {
+               BaseConnection f;
+               if (isSmartHttp(c, service)) {
+                       readSmartHeaders(in, service);
+                       f = new SmartHttpFetchConnection(in);
+               } else {
+                       // Assume this server doesn't support smart HTTP fetch
+                       // and fall back on dumb object walking.
+                       f = newDumbConnection(in);
+               }
+               f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER));
+               return (FetchConnection) f;
+       }
+
        /** {@inheritDoc} */
        @Override
        public FetchConnection openFetch() throws TransportException,
@@ -343,21 +359,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
                final String service = SVC_UPLOAD_PACK;
                try {
                        final HttpConnection c = connect(service);
-                       final InputStream in = openInputStream(c);
-                       try {
-                               BaseConnection f;
-                               if (isSmartHttp(c, service)) {
-                                       readSmartHeaders(in, service);
-                                       f = new SmartHttpFetchConnection(in);
-                               } else {
-                                       // Assume this server doesn't support smart HTTP fetch
-                                       // and fall back on dumb object walking.
-                                       f = newDumbConnection(in);
-                               }
-                               f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER));
-                               return (FetchConnection) f;
-                       } finally {
-                               in.close();
+                       try (InputStream in = openInputStream(c)) {
+                               return getConnection(c, in, service);
                        }
                } catch (NotSupportedException err) {
                        throw err;