From b35c4d64971b1cb61765fa801384ecdc0c7f317f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 25 Oct 2023 21:20:42 -0700 Subject: [PATCH] Open loader jar URLs by default using `runtimeVersion` Update `UrlJarFileFactory` so that `runtimeVersion` is used by default instead of `baseVersion`. Prior to this commit we tried to mirror the JDK handler on look for a `#runtime` fragment. This unfortunately doesn't work with the URLs produced by `URLClassPath`. This commit also fixes a bug in `NestedJarFile` where we didn't return the correct result from `hasEntry`. Fixes gh-38050 --- .../org/springframework/boot/loader/jar/NestedJarFile.java | 2 +- .../boot/loader/net/protocol/jar/UrlJarFileFactory.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/NestedJarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/NestedJarFile.java index 2fe35c46c16..d711b9137a5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/NestedJarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/NestedJarFile.java @@ -230,7 +230,7 @@ public class NestedJarFile extends JarFile { } ZipContent.Entry entry = getVersionedContentEntry(name); if (entry != null) { - return false; + return true; } synchronized (this) { ensureOpen(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/UrlJarFileFactory.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/UrlJarFileFactory.java index 7a45caea98a..35ba9283ca9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/UrlJarFileFactory.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/UrlJarFileFactory.java @@ -58,7 +58,12 @@ class UrlJarFileFactory { } private Runtime.Version getVersion(URL url) { - return "runtime".equals(url.getRef()) ? JarFile.runtimeVersion() : JarFile.baseVersion(); + // The standard JDK handler uses #runtime to indicate that the runtime version + // should be used. This unfortunately doesn't work for us as + // jdk.internal.loaderURLClassPath only adds the runtime fragment when the URL + // is using the internal JDK handler. We need to flip the default to use + // the runtime version. See gh-38050 + return "base".equals(url.getRef()) ? JarFile.baseVersion() : JarFile.runtimeVersion(); } private boolean isLocalFileUrl(URL url) {