]> source.dussan.org Git - jgit.git/commitdiff
RepositoryFilter: Refactor doFilter to open Repository in try-with-resource 02/119302/4
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 13 Mar 2018 08:55:05 +0000 (17:55 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 14 Mar 2018 01:44:23 +0000 (10:44 +0900)
Change-Id: Ic4a056eebe567ff933519d6a805edb7e97c71b22
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java

index c89a5d762c99f9cb5171c3a5385e393a2b29692e..b9e82c27f65f31c7043e47fbcf32fc40bb015f7c 100644 (file)
@@ -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();
                }
        }
 }