JDK-8235783 : DatagramSocket::connect and DatagramSocket::disconnect should allow an implementation to throw UncheckedIOException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 14
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-12-11
  • Updated: 2020-07-09
  • Resolved: 2020-01-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 15
15 b08Fixed
Related Reports
Blocks :  
CSR :  
Relates :  
Sub Tasks
JDK-8247324 :  
Description
DatagramChannel::disconnect  throws IOException while DatagramSocket::disconnect does not. As a result, the DatagramChannel::socket adaptor which calls DatagramChannel::disconnect  currently catches IOException and rethrows it as Error.

On the other hand, DatagramChannel::disconnect has been fixed to rebind the socket in those cases where the underlying platform `disconnect` changes the local socket address. This unfortunately introduce the possibility that `disconnect` will fail. DatagramChannel::disconnect may throw an IOException in that case and its API documentation has been updated to recommend closing the socket if that happens. See JDK-8231260 and JDK-8231259. 

This means that the risk of the DatagramChannel::socket adapter throwing an Error has slightly increased. This is a bit hostile to clients of this API.

The proposal is to change the DatagramChannel::socket adapter to throw UncheckedIOException instead, and update the specification of DatagramSocket::disconnect to document that an implementation may throw UncheckedIOException, and to recommend closing the socket in that case, in much the same way that was done for DatagramChannel.


Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/34138fe5f9f7 User: pconcannon Date: 2020-01-23 14:45:07 +0000
23-01-2020

The 2-arg connect method has the same issue and should probably be re-specified to throw UncheckedIOException or IOError too. The 2-arg connect method and the disconnect method were added together in Java SE 1.2.
11-12-2019