From: David Pursehouse Date: Tue, 20 Mar 2018 02:37:30 +0000 (+0900) Subject: TransportHttp: Refactor to use try-with-resource and suppress resource warning X-Git-Tag: v5.0.0.201805151920-m7~50 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0bc2020412f36b2abf75e5aba1dd318443dbbb10;p=jgit.git TransportHttp: Refactor to use try-with-resource and suppress resource warning Change-Id: I130269e7c5e46aea2152dea6b02539529208eea2 Signed-off-by: David Pursehouse --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index b300d55477..87c328f452 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -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;