From 88429b6a663782129747b12d8983c42bb446cf45 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 17 Dec 2023 10:53:52 -0800 Subject: [PATCH] Use file urls for unpacked jars Update `JarFileArchive` so that unpacked jars use `file:` URLs rather than `jar:file:`. This aligns with the behavior of Spring Boot 3.1 and allows calls to `class.getSigners()` to work again. Fixes gh-38833 --- .../org/springframework/boot/loader/launch/JarFileArchive.java | 2 +- .../boot/loader/launch/JarFileArchiveTests.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/launch/JarFileArchive.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/launch/JarFileArchive.java index 3ccb32009fb3..a38379de908c 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/launch/JarFileArchive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/launch/JarFileArchive.java @@ -113,7 +113,7 @@ private URL getUnpackedNestedJarUrl(JarEntry jarEntry) throws IOException { if (!Files.exists(path) || Files.size(path) != jarEntry.getSize()) { unpack(jarEntry, path); } - return JarUrl.create(path.toFile()); + return path.toUri().toURL(); } private Path getTempUnpackDirectory() { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/JarFileArchiveTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/JarFileArchiveTests.java index ac4a521388a7..94fd60609d91 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/JarFileArchiveTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/JarFileArchiveTests.java @@ -112,7 +112,8 @@ void getClassPathUrlsWhenHasUnpackCommentUnpacksAndReturnsUrls() throws Exceptio assertThat(urls).hasSize(1); URL url = urls.iterator().next(); assertThat(url).isNotEqualTo(JarUrl.create(this.file, "nested.jar")); - assertThat(url.toString()).startsWith("jar:file:").endsWith("/nested.jar!/"); + // The unpack URL must be a raw file URL (see gh-38833) + assertThat(url.toString()).startsWith("file:").endsWith("/nested.jar").doesNotStartWith("jar:"); } @Test