Skip to content

Commit

Permalink
Resolve a resource leak where the ZipFile is not closed (#3618)
Browse files Browse the repository at this point in the history
If th zip entry for resources.arsc is not found an exception is
thrown, but the ZipFile is not closed. Using try-with-resources
means that the ZipFile will always be closed irrespective of how
the code block exits.
  • Loading branch information
alsutton committed Jun 11, 2024
1 parent 4d857db commit c294e01
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public void installFramework(File frameFile) throws AndrolibException {
public void installFramework(File frameFile, String tag) throws AndrolibException {
InputStream in = null;
ZipOutputStream out = null;
try {
ZipFile zip = new ZipFile(frameFile);
try(ZipFile zip = new ZipFile(frameFile)) {
ZipEntry entry = zip.getEntry("resources.arsc");

if (entry == null) {
Expand Down Expand Up @@ -98,7 +97,6 @@ public void installFramework(File frameFile, String tag) throws AndrolibExceptio
out.closeEntry();
}

zip.close();
LOGGER.info("Framework installed to: " + outFile);
} catch (IOException ex) {
throw new AndrolibException(ex);
Expand Down

0 comments on commit c294e01

Please sign in to comment.