RFR[7021373]: DatagramPacket exception conditions are not clear

Daniel Fuchs daniel.fuchs at oracle.com
Fri Jan 24 11:49:28 UTC 2020


Hi Alan,

On 24/01/2020 11:41, Alan Bateman wrote:
>> CSR: https://bugs.openjdk.java.net/browse/JDK-8237774
>> webrev: http://cr.openjdk.java.net/~pconcannon/7021373/webrevs/webrev.00/
> I just skimmed over this (not a complete review) but getSocketAddress() 
> throwing IllegalArgumentException doesn't strange as the method doesn't 
> take any parameters. I assume this is oversight from when this method 
> was added in JDK 1.4. I'm just wondering about the compatibility impact 
> of fixing it to IllegalStateException. An exception here would suggest 
> user error as the datagram packet is only partially setup so the 
> compatibility impact of fixing it is probably low. I'm not saying we do 
> this, just wondering if anything might rely on this (the DatagramSocket 
> socket adaptor case is an outlier).

If I'm not mistaken, one side effect here is that this allows
the DatagramSocketAdaptor to throw IllegalArgumentException when
it is not connected and passed a DatagramPacket in which the port
as not been set.

So modifying the behavior of DatagramPacket::getSocketAddress() would
have an impact on DatagramSocketAdaptor - which would then require
some modification to continue throwing IllegalArgumentException.

I wonder if it might be more prudent to just keep and document
the current behavior.

best regards,

-- daniel



More information about the net-dev mailing list