JDK-8237083 : (dc) Upgrade DatagramChannel socket adaptor to extend MulticastSocket
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.nio
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 15
  • Submitted: 2020-01-14
  • Updated: 2020-01-19
  • Resolved: 2020-01-18
Related Reports
CSR :  
Description
Summary
-------

`java.nio.channels.DatagramChannel::socket` returns a `java.net.DatagramSocket` that allows code using the `DatagramSocket` API to access the channel's socket using the legacy API. This CSR proposes to remove a statement from the `socket` method's javadoc to allow for changes to the implementation, in particular to allow the implementation to return a `java.net.MulticastSocket` (a sub-class of `DatagramSocket`).


Problem
-------

`DatagramChannel::socket` specifies that the returned object (a non-exposed subclass of `DatagramSocket`) does not declare any public methods beyond those specified by `DatagramSocket`. This statement is testable and prevents implementations from implementing additional interfaces beyond those implemented by `DatagramSocket`, or extending it in other ways that define additional public methods.


Solution
--------

Remove the statement from the javadoc that the returned object doesn't declare any public methods beyond those declared by DatagramSocket.

Change the implementation to return a `java.net.MulticastSocket` (a sub-class of `DatagramSocket`). We do not propose to document (in an `@implNote` or elsewhere) that the returned object is an instance of `MulticastSocket`. Users of the API may of course discover this and cast to `java.net.MulticastSocket` of course but it seems unlikely given that `MulticastSocket` is legacy with many deprecated methods.


Specification
-------------

Remove the following statement from the DatagramChannel:socket specification:

"The returned object will not declare any public methods that are not declared in 
the java.net.DatagramSocket class."


Comments
There is no impact to existing code so I wasn't planning to add a RN for this change. I'll think more about it but if we do add a RN then it will need to be clear that this is an implementation detail and libraries should not assume that they can blindly cast the DatagramSocket returned by DatagramChannel::socket to a MulticastSocket.
19-01-2020

Moving to Approved. Please consider a release note for this item.
18-01-2020