Ensure the ZipFile is closed in isZipFile() of ZipDexContainer

When calling isZipFile() in ZipDexContainer, the ZipFile would remain open if
the file was in fact a zip file but the ZipFile object would then go out of
scope thus creating a resource leak. This ensures that the ZipFile is closed
by adding a finally clause containing a close call at the end of the try catch
block.
This commit is contained in:
Albert Gorski 2016-10-09 21:16:54 -04:00 committed by Ben Gruver
parent 5189797292
commit e75f2b230a

View File

@ -123,13 +123,22 @@ public class ZipDexContainer implements MultiDexContainer<ZipDexFile> {
}
public boolean isZipFile() {
ZipFile zipFile = null;
try {
getZipFile();
zipFile = getZipFile();
return true;
} catch (IOException ex) {
return false;
} catch (NotAZipFileException ex) {
return false;
} finally {
if(zipFile != null) {
try {
zipFile.close();
} catch (IOException ex) {
// just eat it
}
}
}
}