RFR 8022126: Remove throws SocketException from DatagramPacket constructors accepting SocketAddress
Chris Hegarty
chris.hegarty at oracle.com
Tue Aug 6 15:32:43 UTC 2013
This is a followup to the recent discussion on:
http://mail.openjdk.java.net/pipermail/net-dev/2013-July/006889.html
(cont'd)
http://mail.openjdk.java.net/pipermail/net-dev/2013-August/006914.html
Two DatagramPacket constructors declare that they throw SocketException.
DatagramPacket(byte[] buf, int len, SocketAddress sa) throws
SocketException
DatagramPacket(byte[] buf, int off, int len, SocketAddress sa)
throws SocketException
As it happens 'throws SE' was incorrectly added to these constructors
when introduced in 1.4. The original API specified that SE was thrown
when the given SocketAddress was not supported. That was later changed
to throw IAE, in 1.4.2. These constructor now can never throw SE.
Removing 'throws SE' from the method declaration is a binary compatible
change, but not source compatible ( XXX is never thrown in body of
corresponding try statement ).
The conclusion of the discussion is that since these constructors are
not that widely used (the InetAddress+port variants are more popular).
Where they are, the affected code typically sends the packet, which
requires handling of IOException anyway.
A note will be added to the jdk8 release notes documenting this
incompatibility.
diff -r 6773af0dda02 src/share/classes/java/net/DatagramPacket.java
--- a/src/share/classes/java/net/DatagramPacket.java Tue Aug 06
15:35:20 2013 +0100
+++ b/src/share/classes/java/net/DatagramPacket.java Tue Aug 06
16:26:38 2013 +0100
@@ -140,7 +140,7 @@ class DatagramPacket {
* @since 1.4
*/
public DatagramPacket(byte buf[], int offset, int length,
- SocketAddress address) throws SocketException {
+ SocketAddress address) {
setData(buf, offset, length);
setSocketAddress(address);
}
@@ -176,7 +176,7 @@ class DatagramPacket {
* @see java.net.InetAddress
*/
public DatagramPacket(byte buf[], int length,
- SocketAddress address) throws SocketException {
+ SocketAddress address) {
this(buf, 0, length, address);
}
-Chris.
More information about the core-libs-dev
mailing list