diff --git a/src/java.base/share/classes/sun/net/NetProperties.java b/src/java.base/share/classes/sun/net/NetProperties.java index eb4fec2d8adb0..9381c437380f1 100644 --- a/src/java.base/share/classes/sun/net/NetProperties.java +++ b/src/java.base/share/classes/sun/net/NetProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,8 +27,6 @@ import jdk.internal.util.StaticProperty; import java.io.*; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Properties; /* @@ -39,17 +37,10 @@ * @author Jean-Christophe Collet * */ - -@SuppressWarnings("removal") public class NetProperties { private static Properties props = new Properties(); static { - AccessController.doPrivileged( - new PrivilegedAction() { - public Void run() { - loadDefaultProperties(); - return null; - }}); + loadDefaultProperties(); } private NetProperties() { }; @@ -82,9 +73,6 @@ private static void loadDefaultProperties() { * returns the default value, if it exists, otherwise returns * null. * @param key the property name. - * @throws SecurityException if a security manager exists and its - * checkPropertiesAccess method doesn't allow access - * to the system properties. * @return the String value for the property, * or null */ @@ -103,9 +91,6 @@ public static String get(String key) { * null. * @param key the property name. * @param defval the default value to use if the property is not found - * @throws SecurityException if a security manager exists and its - * checkPropertiesAccess method doesn't allow access - * to the system properties. * @return the Integer value for the property, * or null */ @@ -131,9 +116,6 @@ public static Integer getInteger(String key, int defval) { * defined returns the default value, if it exists, otherwise returns * null. * @param key the property name. - * @throws SecurityException if a security manager exists and its - * checkPropertiesAccess method doesn't allow access - * to the system properties. * @return the Boolean value for the property, * or null */ diff --git a/src/java.base/share/classes/sun/net/NetworkClient.java b/src/java.base/share/classes/sun/net/NetworkClient.java index 94cf05e60fb30..4f6ec73660de3 100644 --- a/src/java.base/share/classes/sun/net/NetworkClient.java +++ b/src/java.base/share/classes/sun/net/NetworkClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,18 +28,14 @@ import java.net.Socket; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.UnknownHostException; import java.net.Proxy; import java.util.Arrays; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * This is the base class for network clients. * * @author Jonathan Payne */ -@SuppressWarnings("removal") public class NetworkClient { /* Default value of read timeout, if not specified (infinity) */ public static final int DEFAULT_READ_TIMEOUT = -1; @@ -66,26 +62,17 @@ public class NetworkClient { protected static String encoding; static { - final int vals[] = {0, 0}; - final String encs[] = { null }; - - AccessController.doPrivileged( - new PrivilegedAction<>() { - public Void run() { - vals[0] = Integer.getInteger("sun.net.client.defaultReadTimeout", 0).intValue(); - vals[1] = Integer.getInteger("sun.net.client.defaultConnectTimeout", 0).intValue(); - encs[0] = System.getProperty("file.encoding", "ISO8859_1"); - return null; - } - }); - if (vals[0] != 0) { - defaultSoTimeout = vals[0]; + int soTimeout = Integer.getInteger("sun.net.client.defaultReadTimeout", 0); + if (soTimeout != 0) { + defaultSoTimeout = soTimeout; } - if (vals[1] != 0) { - defaultConnectTimeout = vals[1]; + + int connTimeout = Integer.getInteger("sun.net.client.defaultConnectTimeout", 0); + if (connTimeout != 0) { + defaultConnectTimeout = connTimeout; } - encoding = encs[0]; + encoding = System.getProperty("file.encoding", "ISO8859_1"); try { if (!isASCIISuperset (encoding)) { encoding = "ISO8859_1"; @@ -131,7 +118,7 @@ private static boolean isASCIISuperset (String encoding) throws Exception { /** Open a connection to the server. */ public void openServer(String server, int port) - throws IOException, UnknownHostException { + throws IOException { if (serverSocket != null) closeServer(); serverSocket = doConnect (server, port); @@ -150,15 +137,11 @@ public void openServer(String server, int port) * appropriate options pre-established */ protected Socket doConnect (String server, int port) - throws IOException, UnknownHostException { + throws IOException { Socket s; if (proxy != null) { if (proxy.type() == Proxy.Type.SOCKS) { - s = AccessController.doPrivileged( - new PrivilegedAction<>() { - public Socket run() { - return new Socket(proxy); - }}); + s = new Socket(proxy); } else if (proxy.type() == Proxy.Type.DIRECT) { s = createSocket(); } else { @@ -203,13 +186,7 @@ protected Socket createSocket() throws IOException { protected InetAddress getLocalAddress() throws IOException { if (serverSocket == null) throw new IOException("not connected"); - return AccessController.doPrivileged( - new PrivilegedAction<>() { - public InetAddress run() { - return serverSocket.getLocalAddress(); - - } - }); + return serverSocket.getLocalAddress(); } /** Close an open connection to the server. */ diff --git a/src/java.base/share/classes/sun/net/www/http/HttpCapture.java b/src/java.base/share/classes/sun/net/www/http/HttpCapture.java index ba7e5af6cdfc8..7d0254e24f672 100644 --- a/src/java.base/share/classes/sun/net/www/http/HttpCapture.java +++ b/src/java.base/share/classes/sun/net/www/http/HttpCapture.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -65,13 +65,8 @@ public class HttpCapture { private static synchronized void init() { initialized = true; - @SuppressWarnings("removal") - String rulesFile = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction<>() { - public String run() { - return NetProperties.get("sun.net.http.captureRules"); - } - }); + + String rulesFile = NetProperties.get("sun.net.http.captureRules"); if (rulesFile != null && !rulesFile.isEmpty()) { BufferedReader in; try { diff --git a/src/java.base/share/classes/sun/net/www/http/HttpClient.java b/src/java.base/share/classes/sun/net/www/http/HttpClient.java index 01c341401d808..1ab7396ad0636 100644 --- a/src/java.base/share/classes/sun/net/www/http/HttpClient.java +++ b/src/java.base/share/classes/sun/net/www/http/HttpClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,7 +42,6 @@ import sun.net.www.protocol.http.HttpURLConnection; import sun.util.logging.PlatformLogger; import static sun.net.www.protocol.http.HttpURLConnection.TunnelState.*; -import sun.security.action.GetPropertyAction; /** * @author Herb Jellinek @@ -70,10 +69,10 @@ public class HttpClient extends NetworkClient { /** Response code for CONTINUE */ private boolean ignoreContinue = true; - private static final int HTTP_CONTINUE = 100; + private static final int HTTP_CONTINUE = 100; /** Default port number for http daemons. REMIND: make these private */ - static final int httpPortNumber = 80; + static final int httpPortNumber = 80; /** return default port number (subclasses may override) */ protected int getDefaultPort () { return httpPortNumber; } @@ -194,7 +193,7 @@ static String normalizeCBT(String s) { } static { - Properties props = GetPropertyAction.privilegedGetProperties(); + Properties props = System.getProperties(); String keepAlive = props.getProperty("http.keepAlive"); String retryPost = props.getProperty("sun.net.http.retryPost"); String cacheNTLM = props.getProperty("jdk.ntlm.cache"); @@ -243,11 +242,6 @@ public String getSpnegoCBT() { protected HttpClient() { } - private HttpClient(URL url) - throws IOException { - this(url, (String)null, -1, false); - } - protected HttpClient(URL url, boolean proxyDisabled) throws IOException { this(url, null, -1, proxyDisabled); @@ -388,15 +382,6 @@ public static HttpClient New(URL url, Proxy p, int to, boolean useCache, ret.authcache = httpuc.getAuthCache(); } } else { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - if (ret.proxy == Proxy.NO_PROXY || ret.proxy == null) { - security.checkConnect(InetAddress.getByName(url.getHost()).getHostAddress(), url.getPort()); - } else { - security.checkConnect(url.getHost(), url.getPort()); - } - } ret.url = url; } return ret; @@ -571,29 +556,18 @@ public boolean isCachedConnection() { * be done; for proxy tunneling, the socket needs to be converted * into an SSL socket before ssl handshake can take place. */ - public void afterConnect() throws IOException, UnknownHostException { + public void afterConnect() throws IOException { // NO-OP. Needs to be overwritten by HttpsClient } /* - * call openServer in a privileged block + * call openServer */ - @SuppressWarnings("removal") - private void privilegedOpenServer(final InetSocketAddress server) + private void openServer(final InetSocketAddress server) throws IOException { assert clientLock.isHeldByCurrentThread(); - try { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction<>() { - public Void run() throws IOException { - openServer(server.getHostString(), server.getPort()); - return null; - } - }); - } catch (java.security.PrivilegedActionException pae) { - throw (IOException) pae.getException(); - } + openServer(server.getHostString(), server.getPort()); } /* @@ -601,7 +575,7 @@ public Void run() throws IOException { */ private void superOpenServer(final String proxyHost, final int proxyPort) - throws IOException, UnknownHostException + throws IOException { super.openServer(proxyHost, proxyPort); } @@ -610,14 +584,8 @@ private void superOpenServer(final String proxyHost, */ protected void openServer() throws IOException { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - lock(); try { - if (security != null) { - security.checkConnect(host, port); - } if (keepingAlive) { // already opened return; @@ -628,7 +596,7 @@ protected void openServer() throws IOException { if ((proxy != null) && (proxy.type() == Proxy.Type.HTTP)) { sun.net.www.URLConnection.setProxiedHost(host); - privilegedOpenServer((InetSocketAddress) proxy.address()); + openServer((InetSocketAddress) proxy.address()); usingProxy = true; return; } else { @@ -644,7 +612,7 @@ protected void openServer() throws IOException { */ if ((proxy != null) && (proxy.type() == Proxy.Type.HTTP)) { sun.net.www.URLConnection.setProxiedHost(host); - privilegedOpenServer((InetSocketAddress) proxy.address()); + openServer((InetSocketAddress) proxy.address()); usingProxy = true; return; } else { @@ -663,7 +631,7 @@ public String getURLFile() throws IOException { String fileName; - /** + /* * proxyDisabled is set by subclass HttpsClient! */ if (usingProxy && !proxyDisabled) { @@ -817,7 +785,7 @@ private boolean parseHTTPHeader(MessageHeader responses, HttpURLConnection httpu keepAliveConnections = -1; keepAliveTimeout = 0; - boolean ret = false; + boolean ret; byte[] b = new byte[8]; try { diff --git a/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java b/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java index 153de588938ca..41e1e3d0003c2 100644 --- a/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java +++ b/src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java @@ -30,8 +30,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashMap; @@ -39,7 +37,6 @@ import java.util.concurrent.locks.ReentrantLock; import jdk.internal.misc.InnocuousThread; -import sun.security.action.GetIntegerAction; import sun.net.www.protocol.http.HttpURLConnection; import sun.util.logging.PlatformLogger; @@ -69,10 +66,8 @@ public class KeepAliveCache static final PlatformLogger logger = HttpURLConnection.getHttpLogger(); - @SuppressWarnings("removal") static int getUserKeepAliveSeconds(String type) { - int v = AccessController.doPrivileged( - new GetIntegerAction(keepAliveProp+type, -1)).intValue(); + int v = Integer.getInteger(keepAliveProp+type, -1); return v < -1 ? -1 : v; } @@ -89,12 +84,9 @@ static int getUserKeepAliveSeconds(String type) { */ static final int MAX_CONNECTIONS = 5; static int result = -1; - @SuppressWarnings("removal") static int getMaxConnections() { if (result == -1) { - result = AccessController.doPrivileged( - new GetIntegerAction("http.maxConnections", MAX_CONNECTIONS)) - .intValue(); + result = Integer.getInteger("http.maxConnections", MAX_CONNECTIONS); if (result <= 0) { result = MAX_CONNECTIONS; } @@ -119,7 +111,6 @@ public KeepAliveCache() {} * @param url The URL contains info about the host and port * @param http The HttpClient to be cached */ - @SuppressWarnings("removal") public void put(final URL url, Object obj, HttpClient http) { // this method may need to close an HttpClient, either because // it is not cacheable, or because the cache is at its capacity. @@ -144,15 +135,10 @@ public void put(final URL url, Object obj, HttpClient http) { * The robustness to get around this is in HttpClient.parseHTTP() */ final KeepAliveCache cache = this; - AccessController.doPrivileged(new PrivilegedAction<>() { - public Void run() { - keepAliveTimer = InnocuousThread.newSystemThread("Keep-Alive-Timer", cache); - keepAliveTimer.setDaemon(true); - keepAliveTimer.setPriority(Thread.MAX_PRIORITY - 2); - keepAliveTimer.start(); - return null; - } - }); + keepAliveTimer = InnocuousThread.newSystemThread("Keep-Alive-Timer", cache); + keepAliveTimer.setDaemon(true); + keepAliveTimer.setPriority(Thread.MAX_PRIORITY - 2); + keepAliveTimer.start(); } KeepAliveKey key = new KeepAliveKey(url, obj); diff --git a/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java b/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java index 2006dc71de2c0..4ec81e42c3741 100644 --- a/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java +++ b/src/java.base/share/classes/sun/net/www/http/KeepAliveStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -176,16 +176,10 @@ private static void queueForCleanup(KeepAliveCleanerEntry kace) { } if (startCleanupThread) { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - cleanerThread = InnocuousThread.newSystemThread("Keep-Alive-SocketCleaner", queue); - cleanerThread.setDaemon(true); - cleanerThread.setPriority(Thread.MAX_PRIORITY - 2); - cleanerThread.start(); - return null; - } - }); + cleanerThread = InnocuousThread.newSystemThread("Keep-Alive-SocketCleaner", queue); + cleanerThread.setDaemon(true); + cleanerThread.setPriority(Thread.MAX_PRIORITY - 2); + cleanerThread.start(); } } finally { queue.unlock(); diff --git a/src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java b/src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java index 79bdb8cc64f9a..fd3223737b728 100644 --- a/src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java +++ b/src/java.base/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,18 +28,16 @@ import java.io.IOException; import java.util.LinkedList; import sun.net.NetProperties; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; /** - * This class is used to cleanup any remaining data that may be on a KeepAliveStream + * This class is used to clean up any remaining data that may be on a KeepAliveStream * so that the connection can be cached in the KeepAliveCache. * Instances of this class can be used as a FIFO queue for KeepAliveCleanerEntry objects. * Executing this Runnable removes each KeepAliveCleanerEntry from the Queue, reads - * the reamining bytes on its KeepAliveStream, and if successful puts the connection in + * the remaining bytes on its KeepAliveStream, and if successful puts the connection in * the KeepAliveCache. * * @author Chris Hegarty @@ -50,7 +48,7 @@ class KeepAliveStreamCleaner extends LinkedList implements Runnable { - // maximum amount of remaining data that we will try to cleanup + // maximum amount of remaining data that we will try to clean up protected static final int MAX_DATA_REMAINING; // maximum amount of KeepAliveStreams to be queued @@ -64,22 +62,10 @@ class KeepAliveStreamCleaner static { final String maxDataKey = "http.KeepAlive.remainingData"; - @SuppressWarnings("removal") - int maxData = AccessController.doPrivileged( - new PrivilegedAction() { - public Integer run() { - return NetProperties.getInteger(maxDataKey, 512); - }}).intValue() * 1024; - MAX_DATA_REMAINING = maxData; + MAX_DATA_REMAINING = NetProperties.getInteger(maxDataKey, 512) * 1024; final String maxCapacityKey = "http.KeepAlive.queuedConnections"; - @SuppressWarnings("removal") - int maxCapacity = AccessController.doPrivileged( - new PrivilegedAction() { - public Integer run() { - return NetProperties.getInteger(maxCapacityKey, 10); - }}).intValue(); - MAX_CAPACITY = maxCapacity; + MAX_CAPACITY = NetProperties.getInteger(maxCapacityKey, 10); }