Commit c12ccfb3 authored by Andy Wilkinson's avatar Andy Wilkinson

Close JarFile if failure occurs during construction

Fixes gh-17123
parent 4222c5b8
...@@ -118,9 +118,15 @@ public class JarFile extends java.util.jar.JarFile { ...@@ -118,9 +118,15 @@ public class JarFile extends java.util.jar.JarFile {
this.pathFromRoot = pathFromRoot; this.pathFromRoot = pathFromRoot;
CentralDirectoryParser parser = new CentralDirectoryParser(); CentralDirectoryParser parser = new CentralDirectoryParser();
this.entries = parser.addVisitor(new JarFileEntries(this, filter)); this.entries = parser.addVisitor(new JarFileEntries(this, filter));
parser.addVisitor(centralDirectoryVisitor());
this.data = parser.parse(data, filter == null);
this.type = type; 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 : () -> { this.manifestSupplier = (manifestSupplier != null) ? manifestSupplier : () -> {
try (InputStream inputStream = getInputStream(MANIFEST_NAME)) { try (InputStream inputStream = getInputStream(MANIFEST_NAME)) {
if (inputStream == null) { if (inputStream == null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment