From 674022d4014a668f9ff3f2f7837b716667ff6e30 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 17 Aug 2022 11:37:19 -0700 Subject: [PATCH] Revert "Don't close nested jars or wrapper when parent is closed" This reverts commit 360eb027befd51012614f5938fb9cdc9f557a577. --- .../springframework/boot/loader/jar/JarFile.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java index 65450ce3958c..65727df35d0f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java @@ -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; @@ -93,6 +96,8 @@ public class JarFile extends AbstractJarFile implements Iterable nestedJars = Collections.synchronizedList(new ArrayList<>()); + /** * Create a new {@link JarFile} backed by the specified file. * @param file the root jar file @@ -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 @@ -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; } }