RFR: 8356154: Respecify java.net.Socket constructors that allow creating UDP sockets to throw IllegalArgumentException [v3]

Alan Bateman alanb at openjdk.org
Mon May 5 14:03:48 UTC 2025


On Mon, 5 May 2025 12:27:27 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> Can I please get a review of this change which proposes to respecify the 2 `java.net.Socket` constructors that allow construction of UDP sockets? This addresses https://bugs.openjdk.org/browse/JDK-8356154.
>> 
>> As noted in that JBS issue, in Java 23 we deprecated for removal the 2 `Socket` constructors that allowed UDP socket creation. The plan continues to be to remove those constructors. Before removing those, in order to allow for applications to notice this deprecation, these constructors are now being respecified to throw an `IllegalArgumentException` when the `stream` parameter is `false`.
>> 
>> I will create a CSR once we settle on these changes.
>> 
>> tier1 through tier8 tests have been run with this change and no related failures have been noticed.
>
> Jaikiran Pai has updated the pull request incrementally with one additional commit since the last revision:
> 
>   reword SocketImpl.create(...) API doc

src/java.base/share/classes/java/net/Socket.java line 384:

> 382:      * stream socket. Only stream socket creation is allowed. If the stream
> 383:      * argument is {@code false}, then this constructor throws
> 384:      * {@code IllegalArgumentException}.

I would be tempted to drop this paragraph and just change the description of the `@param stream` to say "must be true".

src/java.base/share/classes/java/net/SocketImpl.java line 90:

> 88:      * <p>
> 89:      * This method will be re-specified in a future release to not
> 90:      * support creating datagram sockets.

I think this could do with another round of rewording. I think I would say that the "stream" parameter provided a way in early JDK releases to create a Socket that used a datagram socket. It's no longer possible to do this and therefore this method will only be called by Socket with stream == false.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25031#discussion_r2073493924
PR Review Comment: https://git.openjdk.org/jdk/pull/25031#discussion_r2073508394


More information about the net-dev mailing list