# HG changeset patch # User chegar # Date 1559904687 -3600 # Node ID fe87ca4167530ef0972247cc49b63b9900acfacc # Parent ae41e1037bdeb6753bc6517aa6f49ae6d5d780aa 8216988: ServerSocket.implAccept should include warnings about Socket type/state Reviewed-by: alanb diff -r ae41e1037bde -r fe87ca416753 src/java.base/share/classes/java/net/ServerSocket.java --- a/src/java.base/share/classes/java/net/ServerSocket.java Fri Jun 07 11:47:49 2019 +0100 +++ b/src/java.base/share/classes/java/net/ServerSocket.java Fri Jun 07 11:51:27 2019 +0100 @@ -472,6 +472,12 @@ * 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 @@ /** * 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 empty 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. + * + *
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