Summary
The JDK-specific API jdk.net.Sockets
has been redundant since Java SE 9 added standard methods to get/set socket options and retrieve per-Socket supported options. The proposal is to deprecate the jdk.net.Sockets
class and its public methods.
Problem
The methods of this class have been rendered superfluous since the introduction of standard methods to get, set and retrieve all supported socket options for the calling Socket type i.e. Socket, ServerSocket or DatagramSocket.
For example,
- Socket.getOption(SocketOption name)
- ServerSocket,setOption(SocketOption name, T value)
- DatagramSocket.supportedOptions()
As such, this class and its methods are no longer required.
Solution
The class, jdk.net.Sockets
, and its public methods should all be deprecated with a short note pointing the user to the standardized methods of the appropriate Socket class.
Specification
jdk.net/share/classes/jdk/net/Sockets.java
/**
* Defines static methods to set and get socket options defined by the
* {@link java.net.SocketOption} interface. All of the standard options defined
* by {@link java.net.Socket}, {@link java.net.ServerSocket}, and
* {@link java.net.DatagramSocket} can be set this way, as well as additional
* or platform specific options supported by each socket type.
* <p>
* The {@link #supportedOptions(Class)} method can be called to determine
* the complete set of options available (per socket type) on the
* current system.
* <p>
* When a security manager is installed, some non-standard socket options
* may require a security permission before being set or get.
* The details are specified in {@link ExtendedSocketOptions}. No permission
* is required for {@link java.net.StandardSocketOptions}.
*
+ * @deprecated
+ * Java SE 9 added standard methods to set/get socket options, and retrieve the per-Socket
+ * supported options effectively rendering this API redundant. Please refer to the corresponding
+ * socket's class for the equivalent method to set/get a socket option or retrieve available socket options.
+ *
* @see java.nio.channels.NetworkChannel
*/
+ @Deprecated(since = "16")
public class Sockets {
...
* @throws SecurityException if a security manager is set and the
* caller does not have any required permission.
*
* @throws NullPointerException if name is null
*
+ * @deprecated use {@link java.net.Socket#setOption(SocketOption, Object)} instead.
+ *
* @see java.net.StandardSocketOptions
*/
+ @Deprecated(since = "16")
public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws IOException
...
* @throws SecurityException if a security manager is set and the
* caller does not have any required permission.
*
* @throws NullPointerException if name is null
*
+ * @deprecated use {@link java.net.Socket#getOption(SocketOption)} instead.
+ *
* @see java.net.StandardSocketOptions
*/
+ @Deprecated(since = "16")
public static <T> T getOption(Socket s, SocketOption<T> name) throws IOException
...
* @throws NullPointerException if name is null
*
* @throws SecurityException if a security manager is set and the
* caller does not have any required permission.
*
+ * @deprecated use {@link java.net.ServerSocket#setOption(SocketOption, Object)} instead.
+ *
* @see java.net.StandardSocketOptions
*/
+ @Deprecated(since = "16")
public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value) throws IOException
...
* @throws NullPointerException if name is null
*
* @throws SecurityException if a security manager is set and the
* caller does not have any required permission.
*
+ * @deprecated use {@link java.net.ServerSocket#getOption(SocketOption)} instead.
+ *
* @see java.net.StandardSocketOptions
*/
+ @Deprecated(since = "16")
public static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOException
...
* @throws NullPointerException if name is null
*
* @throws SecurityException if a security manager is set and the
* caller does not have any required permission.
*
+ * @deprecated use {@link java.net.DatagramSocket#setOption(SocketOption, Object)} instead.
+ *
* @see java.net.StandardSocketOptions
*/
+ @Deprecated(since = "16")
public static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value) throws IOException
...
* @throws NullPointerException if name is null
*
* @throws SecurityException if a security manager is set and the
* caller does not have any required permission.
*
+ * @deprecated use {@link java.net.DatagramSocket#getOption(SocketOption)} instead.
+ *
* @see java.net.StandardSocketOptions
*/
+ @Deprecated(since = "16")
public static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOException
...
*
* @param socketType the type of java.net socket
*
* @throws IllegalArgumentException if socketType is not a valid
* socket type from the java.net package.
+ *
+ * @deprecated use {@link Socket#supportedOptions()}, {@link ServerSocket#supportedOptions()},
+ * or {@link DatagramSocket#supportedOptions()} instead.
*/
+ @Deprecated(since = "16", forRemoval=true)
public static Set<SocketOption<?>> supportedOptions(Class<?> socketType) {
- csr of
-
JDK-8189744 Deprecate the JDK-specific API for setting socket options, jdk.net.Sockets
- Closed