Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Mazursky2013-08-27 23:58:56 -0400
committerGerrit Code Review @ Eclipse.org2013-09-09 00:24:31 -0400
commit767faece5c4692748d1ac8e130b2e4c5faa1ff20 (patch)
tree787e93c5bf452b69d28d737a04d57cddae0b7ede /jetty-servlets/src
parentcdd95bb5515f35af090bcbcf6f9af03d5c6762c9 (diff)
downloadorg.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.tar.gz
org.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.tar.xz
org.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.zip
[Bug 415999] Fix some of FindBugs warnings
Mostly not closed streams/DB resources are fixed. But also less important things. Signed-off-by: Mikhail Mazursky <mikhail.mazursky@gmail.com>
Diffstat (limited to 'jetty-servlets/src')
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java7
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PutFilter.java26
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java10
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java15
4 files changed, 33 insertions, 25 deletions
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java
index 9a34873f4e..1ef2cf3f7b 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CGI.java
@@ -409,9 +409,10 @@ public class CGI extends HttpServlet
{
try
{
- Writer outToCgi = new OutputStreamWriter(p.getOutputStream());
- outToCgi.write(input);
- outToCgi.close();
+ try (Writer outToCgi = new OutputStreamWriter(p.getOutputStream()))
+ {
+ outToCgi.write(input);
+ }
}
catch (IOException e)
{
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PutFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PutFilter.java
index 6673168420..f96d29dbec 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PutFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/PutFilter.java
@@ -219,24 +219,26 @@ public class PutFilter implements Filter
if (_putAtomic)
{
File tmp=File.createTempFile(file.getName(),null,_tmpdir);
- OutputStream out = new FileOutputStream(tmp,false);
- if (toRead >= 0)
- IO.copy(in, out, toRead);
- else
- IO.copy(in, out);
- out.close();
+ try (OutputStream out = new FileOutputStream(tmp,false))
+ {
+ if (toRead >= 0)
+ IO.copy(in, out, toRead);
+ else
+ IO.copy(in, out);
+ }
if (!tmp.renameTo(file))
throw new IOException("rename from "+tmp+" to "+file+" failed");
}
else
{
- OutputStream out = new FileOutputStream(file,false);
- if (toRead >= 0)
- IO.copy(in, out, toRead);
- else
- IO.copy(in, out);
- out.close();
+ try (OutputStream out = new FileOutputStream(file,false))
+ {
+ if (toRead >= 0)
+ IO.copy(in, out, toRead);
+ else
+ IO.copy(in, out);
+ }
}
response.setStatus(exists ? HttpServletResponse.SC_OK : HttpServletResponse.SC_CREATED);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java
index 10ec3f62f1..6292fa77a6 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java
@@ -26,6 +26,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
+import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
@@ -95,10 +96,11 @@ public class IncludableGzipFilterTest
testdir.ensureEmpty();
File testFile = testdir.getFile("file.txt");
- BufferedOutputStream testOut = new BufferedOutputStream(new FileOutputStream(testFile));
- ByteArrayInputStream testIn = new ByteArrayInputStream(__content.getBytes("ISO8859_1"));
- IO.copy(testIn,testOut);
- testOut.close();
+ try (OutputStream testOut = new BufferedOutputStream(new FileOutputStream(testFile)))
+ {
+ ByteArrayInputStream testIn = new ByteArrayInputStream(__content.getBytes("ISO8859_1"));
+ IO.copy(testIn,testOut);
+ }
tester=new ServletTester("/context");
tester.getContext().setResourceBase(testdir.getDir().getCanonicalPath());
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java
index 266601b6d6..132db2effd 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.URL;
@@ -193,9 +194,10 @@ public class PutFilterTest
File file=new File(_dir,"file.txt");
assertTrue(file.exists());
- FileInputStream fis = new FileInputStream(file);
- assertEquals(data1,IO.toString(fis));
- fis.close();
+ try (InputStream fis = new FileInputStream(file))
+ {
+ assertEquals(data1,IO.toString(fis));
+ }
request.setMethod("DELETE");
request.setURI("/context/file.txt");
@@ -231,9 +233,10 @@ public class PutFilterTest
File file=new File(_dir,"file.txt");
assertTrue(file.exists());
- FileInputStream fis = new FileInputStream(file);
- assertEquals(data1,IO.toString(fis));
- fis.close();
+ try (InputStream fis = new FileInputStream(file))
+ {
+ assertEquals(data1,IO.toString(fis));
+ }
request.setMethod("MOVE");
request.setURI("/context/file.txt");

Back to the top