RFR 8022126: Remove throws SocketException from DatagramPacket constructors accepting SocketAddress
Alan.Bateman at oracle.com
Tue Aug 6 15:57:17 UTC 2013
On 06/08/2013 08:32, Chris Hegarty wrote:
> This is a followup to the recent discussion on:
> Two DatagramPacket constructors declare that they throw SocketException.
> DatagramPacket(byte buf, int len, SocketAddress sa) throws
> 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
While it a source incompatible change, I think it's the right thing to do.
The patch looks fine to me (if you want then the declaration will
probably fit on one line now).
More information about the core-libs-dev