From: David Pursehouse Date: Tue, 13 Mar 2018 08:55:05 +0000 (+0900) Subject: RepositoryFilter: Refactor doFilter to open Repository in try-with-resource X-Git-Tag: v5.0.0.201805151920-m7~84 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=98667d385149a64ca0be04419e3329472a33892d;p=jgit.git RepositoryFilter: Refactor doFilter to open Repository in try-with-resource Change-Id: Ic4a056eebe567ff933519d6a805edb7e97c71b22 Signed-off-by: David Pursehouse --- diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java index c89a5d762c..b9e82c27f6 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java @@ -140,9 +140,9 @@ public class RepositoryFilter implements Filter { return; } - final Repository db; - try { - db = resolver.open(req, name); + try (Repository db = resolver.open(req, name)) { + request.setAttribute(ATTRIBUTE_REPOSITORY, db); + chain.doFilter(request, response); } catch (RepositoryNotFoundException e) { sendError(req, res, SC_NOT_FOUND); return; @@ -155,13 +155,8 @@ public class RepositoryFilter implements Filter { } catch (ServiceMayNotContinueException e) { sendError(req, res, e.getStatusCode(), e.getMessage()); return; - } - try { - request.setAttribute(ATTRIBUTE_REPOSITORY, db); - chain.doFilter(request, response); } finally { request.removeAttribute(ATTRIBUTE_REPOSITORY); - db.close(); } } }