Skip to content

Commit 674022d

Browse files
committed
Revert "Don't close nested jars or wrapper when parent is closed"
This reverts commit 360eb02.
1 parent 3b01325 commit 674022d

File tree

1 file changed

+14
-1
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar

1 file changed

+14
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
import java.net.URLStreamHandler;
2727
import java.net.URLStreamHandlerFactory;
2828
import java.security.Permission;
29+
import java.util.ArrayList;
30+
import java.util.Collections;
2931
import java.util.Enumeration;
3032
import java.util.Iterator;
33+
import java.util.List;
3134
import java.util.Spliterator;
3235
import java.util.Spliterators;
3336
import java.util.function.Supplier;
@@ -93,6 +96,8 @@ public class JarFile extends AbstractJarFile implements Iterable<java.util.jar.J
9396

9497
private volatile JarFileWrapper wrapper;
9598

99+
private final List<JarFile> nestedJars = Collections.synchronizedList(new ArrayList<>());
100+
96101
/**
97102
* Create a new {@link JarFile} backed by the specified file.
98103
* @param file the root jar file
@@ -335,8 +340,10 @@ private JarFile createJarFileFromFileEntry(JarEntry entry) throws IOException {
335340
+ "mechanism used to create your executable jar file");
336341
}
337342
RandomAccessData entryData = this.entries.getEntryData(entry.getName());
338-
return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName(), entryData,
343+
JarFile nestedJar = new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName(), entryData,
339344
JarFileType.NESTED_JAR);
345+
this.nestedJars.add(nestedJar);
346+
return nestedJar;
340347
}
341348

342349
@Override
@@ -361,6 +368,12 @@ public void close() throws IOException {
361368
if (this.type == JarFileType.DIRECT) {
362369
this.rootFile.close();
363370
}
371+
if (this.wrapper != null) {
372+
this.wrapper.close();
373+
}
374+
for (JarFile nestedJar : this.nestedJars) {
375+
nestedJar.close();
376+
}
364377
this.closed = true;
365378
}
366379
}

0 commit comments

Comments
 (0)