8341551: Revisit jdk.internal.loader.URLClassPath.JarLoader after JEP 486

Reviewed-by: dfuchs, lancea, rriggs, alanb
This commit is contained in:
Jaikiran Pai 2024-12-05 11:19:38 +00:00
parent bcd1018585
commit 01307a7baf
2 changed files with 150 additions and 7 deletions

View file

@ -75,7 +75,7 @@ public class URLClassPath {
private static final String USER_AGENT_JAVA_VERSION = "UA-Java-Version";
private static final String JAVA_VERSION;
private static final boolean DEBUG;
private static final boolean DISABLE_JAR_CHECKING;
private static final boolean JAR_CHECKING_ENABLED;
private static final boolean DISABLE_CP_URL_CHECK;
private static final boolean DEBUG_CP_URL_CHECK;
@ -84,7 +84,9 @@ public class URLClassPath {
JAVA_VERSION = props.getProperty("java.version");
DEBUG = (props.getProperty("sun.misc.URLClassPath.debug") != null);
String p = props.getProperty("sun.misc.URLClassPath.disableJarChecking");
DISABLE_JAR_CHECKING = p != null ? p.equals("true") || p.isEmpty() : false;
// JAR check is disabled by default and will be enabled only if the "disable JAR check"
// system property has been set to "false".
JAR_CHECKING_ENABLED = "false".equals(p);
// This property will be removed in a later release
p = props.getProperty("jdk.net.URLClassPath.disableClassPathURLCheck");
@ -652,11 +654,12 @@ public class URLClassPath {
}
}
/* Throws if the given jar file is does not start with the correct LOC */
@SuppressWarnings("removal")
/*
* Throws an IOException if the LOC file Header Signature (0x04034b50),
* is not found starting at byte 0 of the given jar.
*/
static JarFile checkJar(JarFile jar) throws IOException {
if (System.getSecurityManager() != null && !DISABLE_JAR_CHECKING
&& !zipAccess.startsWithLocHeader(jar)) {
if (JAR_CHECKING_ENABLED && !zipAccess.startsWithLocHeader(jar)) {
IOException x = new IOException("Invalid Jar file");
try {
jar.close();
@ -665,7 +668,6 @@ public class URLClassPath {
}
throw x;
}
return jar;
}