From e7e77a917f3145408f88c1f179a89642855a29ac Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 10 Sep 2020 09:40:44 +0100 Subject: [PATCH] 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] https://github.com/spring-projects/spring-boot/commit/ad72f86bdb9c2a889a76679767e9627de0f2543c [2] https://github.com/spring-projects/spring-boot/commit/ed7a5db17441bdb37df8e90dc0fa6c52948c008e --- .../springframework/boot/loader/Launcher.java | 4 +--- .../boot/loader/PropertiesLauncherTests.java | 9 +++++---- .../resources/nested-jars/nested-jar-app.jar | Bin 0 -> 1408 bytes 3 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/resources/nested-jars/nested-jar-app.jar diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java index d33121ba91..314da4090b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java @@ -80,9 +80,7 @@ public abstract class Launcher { protected ClassLoader createClassLoader(Iterator archives) throws Exception { List 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])); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java index e1c33db7e8..bda4333d11 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java @@ -232,12 +232,13 @@ class PropertiesLauncherTests { @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 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 diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/resources/nested-jars/nested-jar-app.jar b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/resources/nested-jars/nested-jar-app.jar new file mode 100644 index 0000000000000000000000000000000000000000..4c2254f6352b5443de1396397423068a792b2eb5 GIT binary patch literal 1408 zcmWIWW@h1H0D(E)T7h5&l;C8LVeoYgan$wnbJGtE;bdSw{x~uogi9;985mio! z6LHmP3{$f|6@4sX1Um@gryeYRa`N{NLHKDo&;=lj#ZM3;`q7LK1o{bXL~>4IadB!f zBzV>VjaiS+s1`J%#IPBalA4gB1ED*-xG)QotshQ_&__&tA9vBl3fLI-;d5#4I zIho0cC7JnodSEw$W1wL2!5|PuvmiGh)|<&u#CGxO#jmF=%bdT=mgSl=_g*PSmy69I z30Iu`A6uO`@#fs7b%FM)<+!R|uzy*+Xt#8#6LYcsIos#w_J02O^Bdm-hFs}N9nnD7 zwGFA#r6v|(7GaW~+O+~c3OaAwTzxoU?u>;g8s9?{^q2i}aJ!zgfOBKbLZ&vi=j+VH zz8|`(B(d|aMbN<&vpL>gX7_K~Xmqe8x%bn)nQrrJf;)E<$+SgPDrvq~FJhNr?JH%M zzLBCa*L$t+?`tkqCoYz3Xcb%8cFFvmyr$#k?fUG=FOTwUmHc9TNM_@Ii_WF~+_N+< zzP|rh`*GaGH-@Xy zJS73l79b$N@YWGTBjqqwNDf1b4Ty2L@)yK7VB9k-X$0juxN#`C4QMhbw_!CIS4Kg0 z=oO&J@H8J90yGY5mO=O%Gt(d&Ck}Kk+&DxQ0vZd-LU>$>nSqdvO~Pg@G&=#!#+sEt qPR5m)U}l5Db`wssv1BcvWmvLRfHx}}FdP}!fKY;ofgy+)!~+16@N`rF literal 0 HcmV?d00001