Fix unclosed resource warnings

Eclipse Kepler thinks these resources are unclosed.

The refactoring in JettyDaemon combines three duplicate invocations
and confuses Kepler's JDT enough that the unclosed resource warning
goes away.

Change-Id: I0f376ac6116082ed645d6712fe5d98add66f493e
This commit is contained in:
Shawn Pearce 2013-11-28 22:34:32 -08:00
parent 42e2944d3a
commit 0b17d5f178
9 changed files with 21 additions and 13 deletions

View File

@ -36,6 +36,7 @@ public class SshSession {
this.account = account; this.account = account;
} }
@SuppressWarnings("resource")
public String exec(String command) throws JSchException, IOException { public String exec(String command) throws JSchException, IOException {
ChannelExec channel = (ChannelExec) getSession().openChannel("exec"); ChannelExec channel = (ChannelExec) getSession().openChannel("exec");
try { try {

View File

@ -231,6 +231,7 @@ public class CatServlet extends HttpServlet {
CacheHeaders.setNotCacheable(rsp); CacheHeaders.setNotCacheable(rsp);
OutputStream out; OutputStream out;
@SuppressWarnings("resource")
ZipOutputStream zo; ZipOutputStream zo;
final MimeType contentType = registry.getMimeType(path, raw); final MimeType contentType = registry.getMimeType(path, raw);

View File

@ -16,9 +16,7 @@ package com.google.gerrit.httpd.restapi;
import static com.google.common.base.Charsets.UTF_8; import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static java.math.RoundingMode.CEILING; import static java.math.RoundingMode.CEILING;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_CONFLICT; import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
import static javax.servlet.http.HttpServletResponse.SC_CREATED; import static javax.servlet.http.HttpServletResponse.SC_CREATED;
@ -974,6 +972,7 @@ public class RestApiServlet extends HttpServlet {
return asBinaryResult(buf).setContentType(bin.getContentType()); return asBinaryResult(buf).setContentType(bin.getContentType());
} }
@SuppressWarnings("resource")
private static BinaryResult asBinaryResult(final TemporaryBuffer.Heap buf) { private static BinaryResult asBinaryResult(final TemporaryBuffer.Heap buf) {
return new BinaryResult() { return new BinaryResult() {
@Override @Override

View File

@ -181,8 +181,7 @@ public class JettyServer {
if ("http".equals(u.getScheme())) { if ("http".equals(u.getScheme())) {
defaultPort = 80; defaultPort = 80;
c = new ServerConnector(server, null, null, null, 0, acceptors, c = newServerConnector(server, acceptors, config);
new HttpConnectionFactory(config));
} else if ("https".equals(u.getScheme())) { } else if ("https".equals(u.getScheme())) {
SslContextFactory ssl = new SslContextFactory(); SslContextFactory ssl = new SslContextFactory();
@ -217,9 +216,7 @@ public class JettyServer {
} else if ("proxy-http".equals(u.getScheme())) { } else if ("proxy-http".equals(u.getScheme())) {
defaultPort = 8080; defaultPort = 8080;
config.addCustomizer(new ForwardedRequestCustomizer()); config.addCustomizer(new ForwardedRequestCustomizer());
c = new ServerConnector(server, c = newServerConnector(server, acceptors, config);
null, null, null, 0, acceptors,
new HttpConnectionFactory(config));
} else if ("proxy-https".equals(u.getScheme())) { } else if ("proxy-https".equals(u.getScheme())) {
defaultPort = 8080; defaultPort = 8080;
@ -232,9 +229,7 @@ public class JettyServer {
request.setSecure(true); request.setSecure(true);
} }
}); });
c = new ServerConnector(server, c = newServerConnector(server, acceptors, config);
null, null, null, 0, acceptors,
new HttpConnectionFactory(config));
} else { } else {
throw new IllegalArgumentException("Protocol '" + u.getScheme() + "' " throw new IllegalArgumentException("Protocol '" + u.getScheme() + "' "
@ -269,6 +264,12 @@ public class JettyServer {
return connectors; return connectors;
} }
private static ServerConnector newServerConnector(Server server,
int acceptors, HttpConfiguration config) {
return new ServerConnector(server, null, null, null, 0, acceptors,
new HttpConnectionFactory(config));
}
private HttpConfiguration defaultConfig(int requestHeaderSize) { private HttpConfiguration defaultConfig(int requestHeaderSize) {
HttpConfiguration config = new HttpConfiguration(); HttpConfiguration config = new HttpConfiguration();
config.setRequestHeaderSize(requestHeaderSize); config.setRequestHeaderSize(requestHeaderSize);

View File

@ -65,6 +65,7 @@ public class InitPluginStepsLoader {
return pluginsInitSteps; return pluginsInitSteps;
} }
@SuppressWarnings("resource")
private InitStep loadInitStep(File jar) { private InitStep loadInitStep(File jar) {
try { try {
ClassLoader pluginLoader = ClassLoader pluginLoader =

View File

@ -54,6 +54,7 @@ public class JythonShell {
StringBuilder classPath = new StringBuilder(); StringBuilder classPath = new StringBuilder();
final ClassLoader cl = getClass().getClassLoader(); final ClassLoader cl = getClass().getClassLoader();
if (cl instanceof java.net.URLClassLoader) { if (cl instanceof java.net.URLClassLoader) {
@SuppressWarnings("resource")
URLClassLoader ucl = (URLClassLoader) cl; URLClassLoader ucl = (URLClassLoader) cl;
for (URL u : ucl.getURLs()) { for (URL u : ucl.getURLs()) {
if ("file".equals(u.getProtocol())) { if ("file".equals(u.getProtocol())) {

View File

@ -57,6 +57,8 @@ public final class IoUtil {
if (!(cl instanceof URLClassLoader)) { if (!(cl instanceof URLClassLoader)) {
throw noAddURL("Not loaded by URLClassLoader", null); throw noAddURL("Not loaded by URLClassLoader", null);
} }
@SuppressWarnings("resource")
URLClassLoader urlClassLoader = (URLClassLoader) cl; URLClassLoader urlClassLoader = (URLClassLoader) cl;
Method addURL; Method addURL;

View File

@ -59,13 +59,14 @@ public class GetContent implements RestReadView<FileResource> {
} }
try { try {
final ObjectLoader object = repo.open(tw.getObjectId(0)); final ObjectLoader object = repo.open(tw.getObjectId(0));
return new BinaryResult() { @SuppressWarnings("resource")
BinaryResult result = new BinaryResult() {
@Override @Override
public void writeTo(OutputStream os) throws IOException { public void writeTo(OutputStream os) throws IOException {
object.copyTo(os); object.copyTo(os);
} }
}.setContentLength(object.getSize()) };
.base64(); return result.setContentLength(object.getSize()).base64();
} finally { } finally {
tw.release(); tw.release();
} }

View File

@ -51,6 +51,7 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input>,
this.garbageCollectionFactory = garbageCollectionFactory; this.garbageCollectionFactory = garbageCollectionFactory;
} }
@SuppressWarnings("resource")
@Override @Override
public BinaryResult apply(final ProjectResource rsrc, final Input input) { public BinaryResult apply(final ProjectResource rsrc, final Input input) {
return new BinaryResult() { return new BinaryResult() {