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

java.net socket types new-style socket option methods - spec and impl mismatch

XMLWordPrintable

    • b23

        The scope of this issue has been extended to cover the default
        implementation of the three new-style socket option method of
        `SocketImpl` and `DatagramSocketImpl`. The associated CSR contains the
        specific details.

        ---

        The `getOption` and `setOption` methods of the four java.net socket
        types ( ServerSocket, Socket, DatagramSocket, and MulticastSocket ),
        should conform to their specification. Specifically:

        1) Throw NullPointerException if the option name is null.

           Specification:
             * @throws NullPointerException if name is {@code null}

           Example of existing behaviour:
             jshell> (new Socket()).setOption(null, 1);
             | Exception java.lang.UnsupportedOperationException: unsupported option
             | at PlainSocketImpl.setOption (PlainSocketImpl.java:72)
             | at Socket.setOption (Socket.java:1760)
             | at (#2:1)

        2) Throw IllegalArgumentException when passed a bad value.

           A bad value is one of null ( since no specified options accept a
           null value ), or a value outside of the options textually specified
           range, e.g. StandardSocketOptions.SO_SNDBUF specifies "a negative
           size is not allowed". This applied to `setOption` only.

           Specification:
             * @throws IllegalArgumentException if the value is not valid for
             * the option.

           The options that specify, either explicitly or implicitly, a value
           range (in StandardSocketOptions) are SO_RCVBUF, SO_SNDBUF, IP_TOS,
           and IP_MULTICAST_TTL.

           Example of existing behaviour:
             jshell> (new Socket()).setOption(StandardSocketOptions.SO_RCVBUF,-1);
             | Exception java.net.SocketException: bad parameter for SO_SNDBUF or SO_RCVBUF
             | at AbstractPlainSocketImpl.setOption (AbstractPlainSocketImpl.java:289)
             | at SocketImpl.setOption (SocketImpl.java:384)
             | at PlainSocketImpl.setOption (PlainSocketImpl.java:69)
             | at Socket.setOption (Socket.java:1760)
             | at (#1:1)

        3) Throw an IOException after the socket has been closed.

           Specification:
             * @throws IOException if an I/O error occurs, or if the socket is closed.

           Example of existing behaviour:
             jshell> var s = new Socket()
             s ==> Socket[unconnected]
             jshell> s.close()
             jshell> s.getOption(StandardSocketOptions.SO_RCVBUF)
             $8 ==> 131072

              chegar Chris Hegarty
              kganapureddy Krushnareddy Ganapureddy
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: