Skip to content

Commit

Permalink
Revert "Don't close nested jars or wrapper when parent is closed"
Browse files Browse the repository at this point in the history
This reverts commit 360eb02.
  • Loading branch information
philwebb committed Aug 17, 2022
1 parent 3b01325 commit 674022d
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Supplier;
Expand Down Expand Up @@ -93,6 +96,8 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J

private volatile JarFileWrapper wrapper;

private final List<JarFile> nestedJars = Collections.synchronizedList(new ArrayList<>());

/**
* Create a new {@link JarFile} backed by the specified file.
* @param file the root jar file
Expand Down Expand Up @@ -335,8 +340,10 @@ private JarFile createJarFileFromFileEntry(JarEntry entry) throws IOException {
+ "mechanism used to create your executable jar file");
}
RandomAccessData entryData = this.entries.getEntryData(entry.getName());
return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName(), entryData,
JarFile nestedJar = new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName(), entryData,
JarFileType.NESTED_JAR);
this.nestedJars.add(nestedJar);
return nestedJar;
}

@Override
Expand All @@ -361,6 +368,12 @@ public void close() throws IOException {
if (this.type == JarFileType.DIRECT) {
this.rootFile.close();
}
if (this.wrapper != null) {
this.wrapper.close();
}
for (JarFile nestedJar : this.nestedJars) {
nestedJar.close();
}
this.closed = true;
}
}
Expand Down

0 comments on commit 674022d

Please sign in to comment.