Fix remaining try-with-resources warnings

Many of these could be fixed by extracting the conditional object
creation into a method and using that from the try header. One, a lazy
creation of a RevWalk, just does not work with this pattern, so
suppressing the warning is the best we can do.

Change-Id: I7cf2706d282f1851dcf6e1a78ef89eb87a0e8c54
This commit is contained in:
Dave Borowitz
2015-08-28 09:19:48 -04:00
parent b8336f176a
commit 57d5186ab6
7 changed files with 60 additions and 57 deletions

View File

@@ -59,20 +59,8 @@ class InstallPlugin implements RestModifyView<TopLevelResource, Input> {
throw new MethodNotAllowedException("remote installation is disabled");
}
try {
InputStream in;
if (input.raw != null) {
in = input.raw.getInputStream();
} else {
try {
in = new URL(input.url).openStream();
} catch (IOException e) {
throw new BadRequestException(e.getMessage());
}
}
try {
try (InputStream in = openStream(input)) {
loader.installPluginFromStream(name, in);
} finally {
in.close();
}
} catch (PluginInstallException e) {
StringWriter buf = new StringWriter();
@@ -93,6 +81,18 @@ class InstallPlugin implements RestModifyView<TopLevelResource, Input> {
return created ? Response.created(info) : Response.ok(info);
}
private InputStream openStream(Input input)
throws IOException, BadRequestException {
if (input.raw != null) {
return input.raw.getInputStream();
}
try {
return new URL(input.url).openStream();
} catch (IOException e) {
throw new BadRequestException(e.getMessage());
}
}
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
static class Overwrite implements RestModifyView<PluginResource, Input> {
private final PluginLoader loader;