JDK-8230211 : Prepare DatagramSocket for alternative DatagramSocketImpl
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-08-27
  • Updated: 2020-05-18
  • Resolved: 2020-05-18
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
15Fixed
Related Reports
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Blocks :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Evaluate how java.net.DatagramSocket can be simplified to make it a lot easier to replace the underlying implementation. 
Among other things, the following should be considered and evaluated:

1. Drop the support for DatagramSocketImpl implementations that are compiled with JDK 1.3 or older.

2. Drop the filtering when the DatagramSocket is connected. Instead, DatagramSocketImpl.connect should flush the read queue after the address association is setup.

3. Change DatagramSocket.recieve so that the security manager case when not connected always receives into a temporary buffer. This will eliminate the need to peek ahead.

Other preparatory work that could make it easier to provide an alternative implementation should also be considered.
Comments
Fixed as part of JDK-8241072
18-05-2020

If the DatagramSocket wrapper is changed to no longer ever call peek and peekData, it could be a good move to still modify the API documentation of DatagramSocketImpl to allow those methods to throw UnsupportedOperationException, and maybe deprecate them as well.
04-09-2019

So, the assumption is that since the plain-DatagramSocketImpl is not accessible to user code ( it is confined within DatagramSocket ) that it does not have to adhere to the DatagramSocketImpl specification for peek and peekData, right?
04-09-2019

I don't think the DatagramSocketImpl spec will need to be updated, except to clarify how connect can behave when there are datagrams in the read queue. The platform DatagramSocketImpl is internal to the JDK, it should never leak to user code.
04-09-2019

DatagramSocketImpl::peek and DatagramSocketImpl::peekData are public Java SE API's - whether or not their implementation is needed by java.net.DatagramSocket is not the only issue. If these methods are to be optionally implemented, their specification will have to be updated to reflect that.
04-09-2019

Just on point 4, once DatagramSocket is updated then it should not need to use the impl's peek or peekData implementations.
30-08-2019

A few notes, before I forget: 1) DatagramSocketImpl::connect ( and disconnect ) was added in Java 1.4 2) The emulation of connect, in DatagramSocket, is ( at least in part ) due to the fact that the impl may not support connect ( if it was compiled with a JDK less than 1.4 ) 3) If/When support for pre-1.4 impl's is removed, and if connect emulation is also removed, then the DatagramSocket implementation ( and maybe the constructor/connect specification also ) should be updated to actively disallow its creation with a pre-1.4 impl ( or some such change that will not allow a connect call to complete successfully, when it may be ineffectual ). 4) DatagramSocketImpl has API support for peeking, through peek(InetAddress) AND peekData(DatagramPacket). Maybe a new NIO based impl will need new ( currently-does-not-currently-exist ) support in the internal NIO implementation, since DatagramChannel doesn't need it.
30-08-2019