Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse2018-03-13 02:44:23 +0000
committerMatthias Sohn2018-03-13 21:16:06 +0000
commit5c70be00856d5375485e6f062b6e1e09a606601f (patch)
tree55726d1e2a1c52d75460a0a4336d487238037ba6 /org.eclipse.jgit.http.server
parente23b09ad6efc35f6574cfefd4467ad20e5212ff2 (diff)
downloadjgit-5c70be00856d5375485e6f062b6e1e09a606601f.tar.gz
jgit-5c70be00856d5375485e6f062b6e1e09a606601f.tar.xz
jgit-5c70be00856d5375485e6f062b6e1e09a606601f.zip
Open auto-closeable resources in try-with-resource
When an auto-closeable resources is not opened in try-with-resource, the warning "should be managed by try-with-resource" is emitted by Eclipse. Fix the ones that can be silenced simply by moving the declaration of the variable into a try-with-resource. In cases where we explicitly call the close() method, for example in tests where we are testing specific behavior caused by the close(), suppress the warning. Leave the ones that will require more significant refcactoring to fix. They can be done in separate commits that can be reviewed and tested in isolation. Change-Id: I9682cd20fb15167d3c7f9027cecdc82bc50b83c4 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.http.server')
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java5
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java10
2 files changed, 3 insertions, 12 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
index f1ff547ea7..272edc6879 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
@@ -220,12 +220,9 @@ public final class ServletUtils {
public static void send(byte[] content, final HttpServletRequest req,
final HttpServletResponse rsp) throws IOException {
content = sendInit(content, req, rsp);
- final OutputStream out = rsp.getOutputStream();
- try {
+ try (OutputStream out = rsp.getOutputStream()) {
out.write(content);
out.flush();
- } finally {
- out.close();
}
}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
index 4eb94a3a22..ad5e8d479e 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
@@ -110,11 +110,8 @@ class SmartOutputStream extends TemporaryBuffer {
if (256 < out.length() && acceptsGzipEncoding(req)) {
TemporaryBuffer gzbuf = new TemporaryBuffer.Heap(LIMIT);
try {
- GZIPOutputStream gzip = new GZIPOutputStream(gzbuf);
- try {
+ try (GZIPOutputStream gzip = new GZIPOutputStream(gzbuf)) {
out.writeTo(gzip, null);
- } finally {
- gzip.close();
}
if (gzbuf.length() < out.length()) {
out = gzbuf;
@@ -131,12 +128,9 @@ class SmartOutputStream extends TemporaryBuffer {
// hardcoded LIMIT constant above assures us we wouldn't store
// more than 2 GiB of content in memory.
rsp.setContentLength((int) out.length());
- final OutputStream os = rsp.getOutputStream();
- try {
+ try (OutputStream os = rsp.getOutputStream()) {
out.writeTo(os, null);
os.flush();
- } finally {
- os.close();
}
}
}

Back to the top