Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333092

Deprecate for removal Socket constructors to create UDP sockets

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 23
    • core-libs
    • None
    • source
    • minimal
    • Corpus analysis shows extremely few usages of these 2 constructors and thus the compatibility risk is minimal.
    • Java API
    • SE

      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;

            jpai Jaikiran Pai
            alanb Alan Bateman
            Alan Bateman, Daniel Fuchs, Michael McMahon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: