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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user