Browse Source

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
pull/38057/head
Phillip Webb 2 years ago
parent
commit
b35c4d6497
  1. 2
      spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/NestedJarFile.java
  2. 7
      spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/UrlJarFileFactory.java

2
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 { @@ -230,7 +230,7 @@ public class NestedJarFile extends JarFile {
}
ZipContent.Entry entry = getVersionedContentEntry(name);
if (entry != null) {
return false;
return true;
}
synchronized (this) {
ensureOpen();

7
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 { @@ -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) {

Loading…
Cancel
Save