Skip to content

Commit e7e77a9

Browse files
committed
Align PropertiesLauncher's close behavior with JarLauncher
Previously, PropertiesLauncher would close each archive that it iterated over when creating its ClassLoader. This was not aligned with JarLauncher's behaviour and left the ClassLoader with closed archives. The close was introduced in [1] and became more apparent following the change to fail operations on closed archives [2]. This commit updates Launcher to remove the close() that was added in [1]. This aligns the behavior of PropertiesLauncher with JarLauncher and ensures that the ClassLoader does not have entries backed by closed archives on its classpath. Fixes gh-23165 [1] ad72f86 [2] ed7a5db
1 parent 3e0096e commit e7e77a9

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ protected ClassLoader createClassLoader(List<Archive> archives) throws Exception
8080
protected ClassLoader createClassLoader(Iterator<Archive> archives) throws Exception {
8181
List<URL> urls = new ArrayList<>(50);
8282
while (archives.hasNext()) {
83-
Archive archive = archives.next();
84-
urls.add(archive.getUrl());
85-
archive.close();
83+
urls.add(archives.next().getUrl());
8684
}
8785
return createClassLoader(urls.toArray(new URL[0]));
8886
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@ void testUserSpecifiedJarFileWithNestedArchives() throws Exception {
232232

233233
@Test
234234
void testUserSpecifiedNestedJarPath() throws Exception {
235-
System.setProperty("loader.path", "nested-jars/app.jar!/foo.jar");
235+
System.setProperty("loader.path", "nested-jars/nested-jar-app.jar!/BOOT-INF/classes/");
236236
System.setProperty("loader.main", "demo.Application");
237237
this.launcher = new PropertiesLauncher();
238-
List<Archive> archives = new ArrayList<>();
239-
this.launcher.getClassPathArchivesIterator().forEachRemaining(archives::add);
240-
assertThat(archives).hasSize(1).areExactly(1, endingWith("foo.jar!/"));
238+
assertThat(ReflectionTestUtils.getField(this.launcher, "paths").toString())
239+
.isEqualTo("[nested-jars/nested-jar-app.jar!/BOOT-INF/classes/]");
240+
this.launcher.launch(new String[0]);
241+
waitFor("Hello World");
241242
}
242243

243244
@Test

0 commit comments

Comments
 (0)