From 360eb027befd51012614f5938fb9cdc9f557a577 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 15 Aug 2022 17:49:17 -0700 Subject: [PATCH] Don't close nested jars or wrapper when parent is closed Update `JarFile` so that the `close()` method no longer closes nested jars or the wrapper. Prior to this commit it was possible for a parent jar file to be garbage collected and closed even though references still existed to the nested jars. When this happened the nested jars would get closed and any access to entries would result in `JarFile.ensureOpen()` throwing an `IllegalStateException`. The user would often not see this exception directly, but rather find `ClassNotFoundException` being thrown. Fixes gh-31853 --- .../springframework/boot/loader/jar/JarFile.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) 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 65727df35d..65450ce395 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,11 +26,8 @@ import java.net.URL; 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; @@ -96,8 +93,6 @@ 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 @@ -340,10 +335,8 @@ public class JarFile extends AbstractJarFile implements Iterable