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;
}
@SuppressWarnings("resource")
public String exec(String command) throws JSchException, IOException {
ChannelExec channel = (ChannelExec) getSession().openChannel("exec");
try {

View File

@ -231,6 +231,7 @@ public class CatServlet extends HttpServlet {
CacheHeaders.setNotCacheable(rsp);
OutputStream out;
@SuppressWarnings("resource")
ZipOutputStream zo;
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.Preconditions.checkNotNull;
import static java.math.RoundingMode.CEILING;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
import static javax.servlet.http.HttpServletResponse.SC_CREATED;
@ -974,6 +972,7 @@ public class RestApiServlet extends HttpServlet {
return asBinaryResult(buf).setContentType(bin.getContentType());
}
@SuppressWarnings("resource")
private static BinaryResult asBinaryResult(final TemporaryBuffer.Heap buf) {
return new BinaryResult() {
@Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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