Resolve a resource leak where the ZipFile is not closed (#3618)

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.
This commit is contained in:
Al Sutton 2024-06-11 11:42:47 +01:00 committed by GitHub
parent 4d857dbff4
commit c294e014e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,8 +52,7 @@ public class Framework {
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) {
@ -98,7 +97,6 @@ public class Framework {
out.closeEntry();
}
zip.close();
LOGGER.info("Framework installed to: " + outFile);
} catch (IOException ex) {
throw new AndrolibException(ex);