8240533: Inconsistent Exceptions are thrown by DatagramSocket and DatagramChannel when sending a DatagramPacket to port 0

Fix adds checks for port == 0 to the send and connect methods in DatagramSocket and DatagramChannelImpl

Reviewed-by: alanb, chegar, dfuchs, lancea
This commit is contained in:
Patrick Concannon 2020-04-07 16:21:01 +01:00
parent e53ae5ae63
commit 378aef32ab
6 changed files with 560 additions and 0 deletions

View file

@ -188,6 +188,9 @@ public class DatagramSocket implements java.io.Closeable {
}
}
if (port == 0) {
throw new SocketException("Can't connect to port 0");
}
if (!isBound())
bind(new InetSocketAddress(0));
@ -772,6 +775,9 @@ public class DatagramSocket implements java.io.Closeable {
packetPort);
}
}
if (packetPort == 0) {
throw new SocketException("Can't send to port 0");
}
} else {
// we're connected
if (packetAddress == null) {