Summary
The following 2 java.net.Socket
constructors which are currently deprecated will be marked as deprecated for removal:
public Socket(InetAddress host, int port, boolean stream) throws IOException
public Socket(String host, int port, boolean stream) throws IOException
Problem
java.net.Socket
has been primarily used for creating TCP
sockets. However, the Socket
class has 2 constructors that take a boolean
stream
parameter. Passing false
to this parameter constructs a UDP
socket. These 2 constructors, which accept the stream
parameter have been deprecated since Java 1.1. The deprecation points to java.net.DatagramSocket
, which is the standard API for constructing UDP sockets. The use of these 2 constructors hasn't been necessary for dealing with UDP sockets since several releases and thus these should be marked as deprecated for removal to allow for their removal in some subsequent release.
Solution
These 2 constructors will be marked as deprecated for removal.
Specification
diff --git a/src/java.base/share/classes/java/net/Socket.java b/src/java.base/share/classes/java/net/Socket.java
- * @deprecated Use DatagramSocket instead for UDP transport.
+ * @deprecated Use {@link DatagramSocket} instead for UDP transport.
*/
- @Deprecated
+ @Deprecated(forRemoval = true, since = "1.1")
public Socket(String host, int port, boolean stream) throws IOException
...
- * @deprecated Use DatagramSocket instead for UDP transport.
+ * @deprecated Use {@link DatagramSocket} instead for UDP transport.
*/
- @Deprecated
+ @Deprecated(forRemoval = true, since = "1.1")
public Socket(InetAddress host, int port, boolean stream) throws IOException
diff --git a/src/java.base/share/classes/java/net/SocketImpl.java b/src/java.base/share/classes/java/net/SocketImpl.java
/**
* Creates either a stream or a datagram socket.
*
+ * @apiNote
+ * The {@link Socket} constructors to create a datagram socket
+ * are deprecated for removal. This method will be re-specified
+ * in a future release to not support creating datagram sockets.
+ *
* @param stream if {@code true}, create a stream socket;
* otherwise, create a datagram socket.
* @throws IOException if an I/O error occurs while creating the
protected abstract void create(boolean stream) throws IOException;
- csr of
-
JDK-8216984 Deprecate for removal Socket constructors to create UDP sockets
-
- Resolved
-