diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2022-11-20 21:13:50 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-11-21 00:08:38 +0100 |
commit | 3e728166296c08079b3b4b159c4b9fd3f07687e0 (patch) | |
tree | 5bb2cb7e4caeec0eaab1240296512330da5cde00 /org.eclipse.jgit.http.server/src | |
parent | cddff2b7fda1cbfde13e267061fec17cf91a7577 (diff) | |
download | jgit-3e728166296c08079b3b4b159c4b9fd3f07687e0.tar.gz jgit-3e728166296c08079b3b4b159c4b9fd3f07687e0.zip |
UploadPackServlet#doPost use try-with-resource to ensure up is closed
Change-Id: Iadbf81f183bb94f3b00b9940f065586b13e85c95
Diffstat (limited to 'org.eclipse.jgit.http.server/src')
-rw-r--r-- | org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java index b0a07f1d5d..f16e56d949 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java @@ -168,40 +168,41 @@ class UploadPackServlet extends HttpServlet { } UploadPackRunnable r = () -> { - UploadPack up = (UploadPack) req.getAttribute(ATTRIBUTE_HANDLER); - // to be explicitly closed by caller - @SuppressWarnings("resource") - SmartOutputStream out = new SmartOutputStream(req, rsp, false) { - @Override - public void flush() throws IOException { - doFlush(); - } - }; + upload(req, rsp); + }; + handler.upload(req, rsp, r); + } + + private void upload(HttpServletRequest req, HttpServletResponse rsp) + throws IOException, ServiceMayNotContinueException { + // to be explicitly closed by caller + @SuppressWarnings("resource") + SmartOutputStream out = new SmartOutputStream(req, rsp, false) { + @Override + public void flush() throws IOException { + doFlush(); + } + }; + Repository repo = null; + try (UploadPack up = (UploadPack) req.getAttribute(ATTRIBUTE_HANDLER)) { up.setBiDirectionalPipe(false); rsp.setContentType(UPLOAD_PACK_RESULT_TYPE); - - try { - up.uploadWithExceptionPropagation(getInputStream(req), out, - null); - out.close(); - } catch (ServiceMayNotContinueException e) { - if (e.isOutput()) { - consumeRequestBody(req); - out.close(); - } - throw e; - } catch (UploadPackInternalServerErrorException e) { - // Special case exception, error message was sent to client. - log(up.getRepository(), e.getCause()); + repo = up.getRepository(); + up.uploadWithExceptionPropagation(getInputStream(req), out, null); + out.close(); + } catch (ServiceMayNotContinueException e) { + if (e.isOutput()) { consumeRequestBody(req); out.close(); - } finally { - up.close(); } - }; - - handler.upload(req, rsp, r); + throw e; + } catch (UploadPackInternalServerErrorException e) { + // Special case exception, error message was sent to client. + log(repo, e.getCause()); + consumeRequestBody(req); + out.close(); + } } private void defaultUploadPackHandler(HttpServletRequest req, |