diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/SshSession.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/SshSession.java index a150eba6d0..dc648fcd82 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/SshSession.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/SshSession.java @@ -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 { diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/CatServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/CatServlet.java index 47a9263209..9aec609bdd 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/CatServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/CatServlet.java @@ -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); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java index 2e1cc0663d..636ccaf48c 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java @@ -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 diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java index b8a3a26736..4a191099c4 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java @@ -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); diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java index 6b4cedf758..85a8ee307a 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java @@ -65,6 +65,7 @@ public class InitPluginStepsLoader { return pluginsInitSteps; } + @SuppressWarnings("resource") private InitStep loadInitStep(File jar) { try { ClassLoader pluginLoader = diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/shell/JythonShell.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/shell/JythonShell.java index 4ad91d9bf2..dfe28b7106 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/shell/JythonShell.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/shell/JythonShell.java @@ -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())) { diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/IoUtil.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/IoUtil.java index e28af7c057..1c3d1e3866 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/IoUtil.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/IoUtil.java @@ -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; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetContent.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetContent.java index f0d229730f..c0e3d68a27 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetContent.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetContent.java @@ -59,13 +59,14 @@ public class GetContent implements RestReadView { } 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(); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java index 07ac0fb8f6..ad20a8dd1f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java @@ -51,6 +51,7 @@ public class GarbageCollect implements RestModifyView, this.garbageCollectionFactory = garbageCollectionFactory; } + @SuppressWarnings("resource") @Override public BinaryResult apply(final ProjectResource rsrc, final Input input) { return new BinaryResult() {