Close JarFile if failure occurs during construction

Fixes gh-17123
This commit is contained in:
Andy Wilkinson 2019-06-12 12:59:14 +01:00
parent 4222c5b8ce
commit c12ccfb342
1 changed files with 8 additions and 2 deletions

View File

@ -118,9 +118,15 @@ public class JarFile extends java.util.jar.JarFile {
this.pathFromRoot = pathFromRoot;
CentralDirectoryParser parser = new CentralDirectoryParser();
this.entries = parser.addVisitor(new JarFileEntries(this, filter));
parser.addVisitor(centralDirectoryVisitor());
this.data = parser.parse(data, filter == null);
this.type = type;
parser.addVisitor(centralDirectoryVisitor());
try {
this.data = parser.parse(data, filter == null);
}
catch (RuntimeException ex) {
close();
throw ex;
}
this.manifestSupplier = (manifestSupplier != null) ? manifestSupplier : () -> {
try (InputStream inputStream = getInputStream(MANIFEST_NAME)) {
if (inputStream == null) {