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
This commit is contained in:
Phillip Webb 2023-10-25 21:20:42 -07:00
parent 464523ac04
commit b35c4d6497
2 changed files with 7 additions and 2 deletions

View File

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

View File

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