8344188: Cleanup sun.net.www.protocol.jar.JarFileFactory after JEP 486 integration

Reviewed-by: jpai, dfuchs
This commit is contained in:
Eirik Bjørsnøs 2024-11-15 12:18:53 +00:00
parent ba39321902
commit 5e2760856c

View File

@ -31,7 +31,6 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.jar.JarFile;
import java.security.Permission;
import jdk.internal.util.OperatingSystem;
import sun.net.util.URLUtil;
@ -219,35 +218,7 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
private JarFile getCachedJarFile(URL url) {
assert Thread.holdsLock(instance);
JarFile result = fileCache.get(urlKey(url));
/* if the JAR file is cached, the permission will always be there */
if (result != null) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
Permission perm = getPermission(result);
if (perm != null) {
try {
sm.checkPermission(perm);
} catch (SecurityException se) {
// fallback to checkRead/checkConnect for pre 1.2
// security managers
if ((perm instanceof java.io.FilePermission) &&
perm.getActions().contains("read")) {
sm.checkRead(perm.getName());
} else if ((perm instanceof
java.net.SocketPermission) &&
perm.getActions().contains("connect")) {
sm.checkConnect(url.getHost(), url.getPort());
} else {
throw se;
}
}
}
}
}
return result;
return fileCache.get(urlKey(url));
}
private String urlKey(URL url) {
@ -255,16 +226,4 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
if ("runtime".equals(url.getRef())) urlstr += "#runtime";
return urlstr;
}
private Permission getPermission(JarFile jarFile) {
try {
URLConnection uc = getConnection(jarFile);
if (uc != null)
return uc.getPermission();
} catch (IOException ioe) {
// gulp
}
return null;
}
}