8222829: DatagramSocket.setSoTimeout does not specify IAE when timeout is negative

Clarifies behaviour of setSoTimeout() method when given negative timeout value.

Reviewed-by: alanb, chegar, dfuchs
This commit is contained in:
Patrick Concannon 2019-10-08 15:03:20 +01:00
parent ee87f2a7a4
commit dcceed10b6
2 changed files with 45 additions and 18 deletions

View file

@ -899,12 +899,15 @@ class DatagramSocket implements java.io.Closeable {
*
* @param timeout the specified timeout in milliseconds.
* @throws SocketException if there is an error in the underlying protocol, such as an UDP error.
* @throws IllegalArgumentException if {@code timeout} is negative
* @since 1.1
* @see #getSoTimeout()
*/
public synchronized void setSoTimeout(int timeout) throws SocketException {
if (isClosed())
throw new SocketException("Socket is closed");
if (timeout < 0)
throw new IllegalArgumentException("timeout < 0");
getImpl().setOption(SocketOptions.SO_TIMEOUT, timeout);
}