Skip to content

Commit 2a37b2e

Browse files
committed
Refine PropertiesLauncher close logic
Further attempt to fix Windows file issues. See gh-21575
1 parent 1e7da4d commit 2a37b2e

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
import java.util.ArrayList;
3030
import java.util.Collections;
3131
import java.util.Iterator;
32-
import java.util.LinkedHashMap;
3332
import java.util.LinkedHashSet;
3433
import java.util.List;
3534
import java.util.Locale;
36-
import java.util.Map;
3735
import java.util.Properties;
3836
import java.util.Set;
3937
import java.util.jar.Manifest;
@@ -531,7 +529,7 @@ private class ClassPathArchives implements Iterable<Archive> {
531529

532530
private final List<Archive> classPathArchives;
533531

534-
private final Map<File, JarFileArchive> jarFileArchives = new LinkedHashMap<>();
532+
private final List<JarFileArchive> jarFileArchives = new ArrayList<>();
535533

536534
ClassPathArchives() throws Exception {
537535
this.classPathArchives = new ArrayList<>();
@@ -666,11 +664,8 @@ private List<Archive> asList(Iterator<Archive> iterator) {
666664
}
667665

668666
private JarFileArchive getJarFileArchive(File file) throws IOException {
669-
JarFileArchive archive = this.jarFileArchives.get(file);
670-
if (archive == null) {
671-
archive = new JarFileArchive(file);
672-
this.jarFileArchives.put(file, archive);
673-
}
667+
JarFileArchive archive = new JarFileArchive(file);
668+
this.jarFileArchives.add(archive);
674669
return archive;
675670
}
676671

@@ -680,7 +675,7 @@ public Iterator<Archive> iterator() {
680675
}
681676

682677
void close() throws IOException {
683-
for (JarFileArchive archive : this.jarFileArchives.values()) {
678+
for (JarFileArchive archive : this.jarFileArchives) {
684679
archive.close();
685680
}
686681
}

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ void loadResourceFromJarFile() throws Exception {
389389
this.launcher.launch(new String[0]);
390390
}
391391
catch (Exception ex) {
392+
// Expected ClassNotFoundException
393+
LaunchedURLClassLoader classLoader = (LaunchedURLClassLoader) Thread.currentThread()
394+
.getContextClassLoader();
395+
classLoader.close();
392396
}
393397
URL resource = new URL("jar:" + jarFile.toURI() + "!/nested.jar!/3.dat");
394398
byte[] bytes = FileCopyUtils.copyToByteArray(resource.openStream());

0 commit comments

Comments
 (0)