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

Michael McMahon michaelm at openjdk.org
Tue May 6 13:14:29 UTC 2025


On Tue, 6 May 2025 09:11:32 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:
> 
>   remove unintentional file additions

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

> 388:      * The {@code stream} parameter provided a way in early JDK releases
> 389:      * to create a {@code Socket} that used a datagram socket, this feature
> 390:      * no longer exists.

Suggestion:

     * to create a {@code Socket} that used a datagram socket. This feature
     * no longer exists.

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

> 420:      * The {@code stream} parameter provided a way in early JDK releases
> 421:      * to create a {@code Socket} that used a datagram socket, this feature
> 422:      * no longer exists.

Suggestion:

     * to create a {@code Socket} that used a datagram socket. This feature
     * no longer exists.

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

> 453:         if (!stream) {
> 454:             throw new IllegalArgumentException(
> 455:                     "Socket constructor does not support creation of datagram socket");

Suggestion:

                    "Socket constructor does not support creation of datagram sockets");

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25031#discussion_r2075440810
PR Review Comment: https://git.openjdk.org/jdk/pull/25031#discussion_r2075441407
PR Review Comment: https://git.openjdk.org/jdk/pull/25031#discussion_r2075443704


More information about the nio-dev mailing list