8345223: Remove stray doPrivileged in java.base java.net and sun.net classes after JEP 486 integration

Reviewed-by: alanb, aefimov, michaelm
This commit is contained in:
Daniel Fuchs 2024-11-29 15:58:57 +00:00
parent a80ccf2cd2
commit e9136b5e08
6 changed files with 30 additions and 92 deletions

View file

@ -42,7 +42,6 @@ import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import sun.net.util.IPAddressUtil;
import sun.net.PortConfig;
import sun.security.action.GetBooleanAction;
import sun.security.util.RegisteredDomain;
import sun.security.util.SecurityConstants;
import sun.security.util.Debug;
@ -211,7 +210,8 @@ public final class SocketPermission extends Permission
private transient boolean trusted;
// true if the sun.net.trustNameService system property is set
private static final boolean trustNameService = GetBooleanAction.privilegedGetProperty("sun.net.trustNameService");
private static final boolean trustNameService =
Boolean.getBoolean("sun.net.trustNameService");
private static Debug debug = null;
private static boolean debugInit = false;

View file

@ -710,13 +710,13 @@ public class FtpClient extends sun.net.ftp.FtpClient {
} else if (address.isLoopbackAddress() && s.startsWith("127.")) { // can be 127.0
return new InetSocketAddress(s, port);
} else if (address.isLoopbackAddress()) {
if (privilegedLocalHost().getHostAddress().equals(s)) {
if (getLocalHost().getHostAddress().equals(s)) {
return new InetSocketAddress(s, port);
} else {
throw new FtpProtocolException(ERROR_MSG);
}
} else if (s.startsWith("127.")) {
if (privilegedLocalHost().equals(address)) {
if (getLocalHost().equals(address)) {
return new InetSocketAddress(s, port);
} else {
throw new FtpProtocolException(ERROR_MSG);
@ -724,7 +724,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
}
String hostName = address.getHostName();
if (!(IPAddressUtil.isIPv4LiteralAddress(hostName) || IPAddressUtil.isIPv6LiteralAddress(hostName))) {
InetAddress[] names = privilegedGetAllByName(hostName);
InetAddress[] names = getAllByName(hostName);
String resAddress = Arrays
.stream(names)
.map(InetAddress::getHostAddress)
@ -738,7 +738,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
throw new FtpProtocolException(ERROR_MSG);
}
private static InetAddress privilegedLocalHost() throws FtpProtocolException {
private static InetAddress getLocalHost() throws FtpProtocolException {
try {
return InetAddress.getLocalHost();
} catch (Exception e) {
@ -748,7 +748,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
}
}
private static InetAddress[] privilegedGetAllByName(String hostName) throws FtpProtocolException {
private static InetAddress[] getAllByName(String hostName) throws FtpProtocolException {
try {
return InetAddress.getAllByName(hostName);
} catch (Exception e) {