RFR[7021373]: DatagramPacket exception conditions are not clear

Patrick Concannon patrick.concannon at oracle.com
Mon Jan 27 17:27:46 UTC 2020


Hi,

Thanks everyone for the feedback.

Chris, I've incorporated the changes you asked for, and they can be 
found in the updated webrev here: 
http://cr.openjdk.java.net/~pconcannon/7021373/webrevs/webrev.01/


I’ve taken the @throws IAE from DatagramPacket::getSocketAddress, and 
logged it as a separate issue as it seems further work is needed in 
deciding how to move forward with it. See 
https://bugs.openjdk.java.net/browse/JDK-8237890


Kind regards,

Patrick

On 24/01/2020 16:36, Chris Hegarty wrote:
> Maybe we can retain existing behaviour, while implicitly specifying 
> the IAE?
>
>
> @@ -311,16 +312,21 @@
> setAddress(addr.getAddress());
> setPort(addr.getPort());
>      }
>
>
>      /**
>       * Gets the SocketAddress (usually IP address + port number) of 
> the remote
>       * host that this packet is being sent to or is coming from.
>       *
> +     * <p> This method is the equivalent to invoking:
> +     * <pre> {@code
> +     *     new InetSocketAddress(getAddress(), getPort())
> +     * }</pre>
> +     *
>       * @return the {@code SocketAddress}
>       * @since 1.4
>       * @see #setSocketAddress
>       */
>      public synchronized SocketAddress getSocketAddress() {
>          return new InetSocketAddress(getAddress(), getPort());
>      }
>
> This approach leans on the behaviour of other existing methods,
> and show up further gaps in their specifications ( which should
> be resolved anyway ) [*]
>
> [*]
>      /**
>       * Returns the IP address of the machine to which this datagram 
> is being
>       * sent or from which the datagram was received.
>       *
>       * @return  the IP address of the machine to which this datagram 
> is being
> -     *          sent or from which the datagram was received.
> +     *          sent or from which the datagram was received; may be null
>       * @see     java.net.InetAddress
>       * @see #setAddress(java.net.InetAddress)
>       */
>      public synchronized InetAddress getAddress() {
>          return address;
>      }
>
>      /**
>       * Returns the port number on the remote host to which this 
> datagram is
>       * being sent or from which the datagram was received.
>       *
>       * @return  the port number on the remote host to which this 
> datagram is
> -     *          being sent or from which the datagram was received.
> +     *          being sent or from which the datagram was received; 
> {@code -1}
> +     *          if not set
>       * @see #setPort(int)
>       */
>      public synchronized int getPort() {
>          return port;
>      }
>
>      /**
>       * Returns the data buffer. The data received or the data to be sent
> -Chris.
>
>
>> On 24 Jan 2020, at 12:26, Alan Bateman <Alan.Bateman at oracle.com 
>> <mailto:Alan.Bateman at oracle.com>> wrote:
>>
>> On 24/01/2020 11:49, Daniel Fuchs wrote:
>>>
>>> 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.
>> Yes, that's the outlier I mentioned in the reply (that usage should 
>> probably be changed anyway as the send shouldn't be create a 
>> SocketAddress).
>>
>>> :
>>>
>>> I wonder if it might be more prudent to just keep and document
>>> the current behavior.
>> Maybe. We normally default to specifying the long standing behavior 
>> but there are cases where the risk of fixing an issue is very low, 
>> e.g DatagramSocket.send was changed recently to throw IAE for a case 
>> that was previously unspecified and where the implementation threw an 
>> accidental NPE.
>> -Alan.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20200127/9a2f41c7/attachment.htm>


More information about the net-dev mailing list