Skip to content

Commit

Permalink
Align PropertiesLauncher's close behavior with JarLauncher
Browse files Browse the repository at this point in the history
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 spring-projectsgh-23165

[1] spring-projects@ad72f86
[2] spring-projects@ed7a5db
  • Loading branch information
wilkinsona committed Sep 10, 2020
1 parent 3e0096e commit e7e77a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ protected ClassLoader createClassLoader(List<Archive> archives) throws Exception
protected ClassLoader createClassLoader(Iterator<Archive> archives) throws Exception {
List<URL> urls = new ArrayList<>(50);
while (archives.hasNext()) {
Archive archive = archives.next();
urls.add(archive.getUrl());
archive.close();
urls.add(archives.next().getUrl());
}
return createClassLoader(urls.toArray(new URL[0]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,13 @@ void testUserSpecifiedJarFileWithNestedArchives() throws Exception {

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

@Test
Expand Down
Binary file not shown.

0 comments on commit e7e77a9

Please sign in to comment.