Browse Source

RepositoryFilter: Refactor doFilter to open Repository in try-with-resource

Change-Id: Ic4a056eebe567ff933519d6a805edb7e97c71b22
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.0
David Pursehouse 7 years ago
parent
commit
98667d3851
  1. 11
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java

11
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();
}
}
}

Loading…
Cancel
Save