8216988: ServerSocket.implAccept should include warnings about Socket type/state

Reviewed-by: alanb
This commit is contained in:
Chris Hegarty 2019-06-07 11:51:27 +01:00
parent 2edcc74725
commit 752cefa3f2

View File

@ -472,6 +472,12 @@ class ServerSocket implements java.io.Closeable {
* as its arguments to ensure the operation is allowed.
* This could result in a SecurityException.
*
* @implNote
* An instance of this class using a system-default {@code SocketImpl}
* accepts sockets with a {@code SocketImpl} of the same type, regardless
* of the {@linkplain Socket#setSocketImplFactory(SocketImplFactory)
* client socket implementation factory}, if one has been set.
*
* @exception IOException if an I/O error occurs when waiting for a
* connection.
* @exception SecurityException if a security manager exists and its
@ -501,15 +507,33 @@ class ServerSocket implements java.io.Closeable {
/**
* Subclasses of ServerSocket use this method to override accept()
* to return their own subclass of socket. So a FooServerSocket
* will typically hand this method an <i>empty</i> FooSocket. On
* return from implAccept the FooSocket will be connected to a client.
* will typically hand this method a newly created, unbound, FooSocket.
* On return from implAccept the FooSocket will be connected to a client.
*
* <p> The behavior of this method is unspecified when invoked with a
* socket that is not newly created and unbound. Any socket options set
* on the given socket prior to invoking this method may or may not be
* preserved when the connection is accepted. It may not be possible to
* accept a connection when this socket has a {@code SocketImpl} of one
* type and the given socket has a {@code SocketImpl} of a completely
* different type.
*
* @implNote
* An instance of this class using a system-default {@code SocketImpl}
* can accept a connection with a Socket using a {@code SocketImpl} of
* the same type: {@code IOException} is thrown if the Socket is using
* a custom {@code SocketImpl}. An instance of this class using a
* custom {@code SocketImpl} cannot accept a connection with a Socket
* using a system-default {@code SocketImpl}.
*
* @param s the Socket
* @throws java.nio.channels.IllegalBlockingModeException
* if this socket has an associated channel,
* and the channel is in non-blocking mode
* @throws IOException if an I/O error occurs when waiting
* for a connection.
* for a connection, or if it is not possible for this socket
* to accept a connection with the given socket
*
* @since 1.1
* @revised 1.4
* @spec JSR-51