Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 56d8e8a

Browse files
committed
8189744: Deprecate the JDK-specific API for setting socket options, jdk.net.Sockets
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. This fix deprecates the class and its public methods. Reviewed-by: chegar, dfuchs
1 parent 0831098 commit 56d8e8a

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/jdk.net/share/classes/jdk/net/Sockets.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@
2525

2626
package jdk.net;
2727

28-
import java.net.*;
28+
import jdk.net.ExtendedSocketOptions.PlatformSocketOptions;
29+
2930
import java.io.IOException;
31+
import java.net.DatagramSocket;
32+
import java.net.MulticastSocket;
33+
import java.net.ServerSocket;
34+
import java.net.Socket;
35+
import java.net.SocketOption;
36+
import java.net.StandardSocketOptions;
3037
import java.util.Collections;
3138
import java.util.HashMap;
3239
import java.util.HashSet;
3340
import java.util.Map;
3441
import java.util.Set;
35-
import jdk.net.ExtendedSocketOptions.PlatformSocketOptions;
3642

3743
/**
3844
* Defines static methods to set and get socket options defined by the
@@ -50,8 +56,14 @@
5056
* The details are specified in {@link ExtendedSocketOptions}. No permission
5157
* is required for {@link java.net.StandardSocketOptions}.
5258
*
59+
* @deprecated
60+
* Java SE 9 added standard methods to set/get socket options, and retrieve the per-Socket
61+
* supported options effectively rendering this API redundant. Please refer to the corresponding
62+
* socket's class for the equivalent method to set/get a socket option or retrieve available socket options.
63+
*
5364
* @see java.nio.channels.NetworkChannel
5465
*/
66+
@Deprecated(since = "16")
5567
public class Sockets {
5668

5769
private static final Map<Class<?>,Set<SocketOption<?>>>
@@ -80,8 +92,11 @@ private Sockets() {}
8092
*
8193
* @throws NullPointerException if name is null
8294
*
95+
* @deprecated use {@link java.net.Socket#setOption(SocketOption, Object)} instead.
96+
*
8397
* @see java.net.StandardSocketOptions
8498
*/
99+
@Deprecated(since = "16")
85100
public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws IOException
86101
{
87102
s.setOption(name, value);
@@ -105,8 +120,11 @@ public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws
105120
*
106121
* @throws NullPointerException if name is null
107122
*
123+
* @deprecated use {@link java.net.Socket#getOption(SocketOption)} instead.
124+
*
108125
* @see java.net.StandardSocketOptions
109126
*/
127+
@Deprecated(since = "16")
110128
public static <T> T getOption(Socket s, SocketOption<T> name) throws IOException
111129
{
112130
return s.getOption(name);
@@ -132,8 +150,11 @@ public static <T> T getOption(Socket s, SocketOption<T> name) throws IOException
132150
* @throws SecurityException if a security manager is set and the
133151
* caller does not have any required permission.
134152
*
153+
* @deprecated use {@link java.net.ServerSocket#setOption(SocketOption, Object)} instead.
154+
*
135155
* @see java.net.StandardSocketOptions
136156
*/
157+
@Deprecated(since = "16")
137158
public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value) throws IOException
138159
{
139160
s.setOption(name, value);
@@ -157,8 +178,11 @@ public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value)
157178
* @throws SecurityException if a security manager is set and the
158179
* caller does not have any required permission.
159180
*
181+
* @deprecated use {@link java.net.ServerSocket#getOption(SocketOption)} instead.
182+
*
160183
* @see java.net.StandardSocketOptions
161184
*/
185+
@Deprecated(since = "16")
162186
public static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOException
163187
{
164188
return s.getOption(name);
@@ -185,8 +209,11 @@ public static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOExc
185209
* @throws SecurityException if a security manager is set and the
186210
* caller does not have any required permission.
187211
*
212+
* @deprecated use {@link java.net.DatagramSocket#setOption(SocketOption, Object)} instead.
213+
*
188214
* @see java.net.StandardSocketOptions
189215
*/
216+
@Deprecated(since = "16")
190217
public static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value) throws IOException
191218
{
192219
s.setOption(name, value);
@@ -211,8 +238,11 @@ public static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value
211238
* @throws SecurityException if a security manager is set and the
212239
* caller does not have any required permission.
213240
*
241+
* @deprecated use {@link java.net.DatagramSocket#getOption(SocketOption)} instead.
242+
*
214243
* @see java.net.StandardSocketOptions
215244
*/
245+
@Deprecated(since = "16")
216246
public static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOException
217247
{
218248
return s.getOption(name);
@@ -227,7 +257,11 @@ public static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOE
227257
*
228258
* @throws IllegalArgumentException if socketType is not a valid
229259
* socket type from the java.net package.
260+
*
261+
* @deprecated use {@link Socket#supportedOptions()}, {@link ServerSocket#supportedOptions()},
262+
* or {@link DatagramSocket#supportedOptions()} instead.
230263
*/
264+
@Deprecated(since = "16", forRemoval=true)
231265
public static Set<SocketOption<?>> supportedOptions(Class<?> socketType) {
232266
Set<SocketOption<?>> set = options.get(socketType);
233267
if (set == null) {

0 commit comments

Comments
 (0)