-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8356154: Respecify java.net.Socket constructors that allow creating UDP sockets to throw IllegalArgumentException #25031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…DP sockets to throw IllegalArgumentException
/csr |
👋 Welcome back jpai! A progress list of the required criteria for merging this PR into |
@jaikiran This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 64 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@jaikiran has indicated that a compatibility and specification (CSR) request is needed for this pull request. @jaikiran please create a CSR request for issue JDK-8356154 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
Webrevs
|
@@ -451,19 +449,20 @@ private void write(byte[] b, int off, int len) throws IOException { | |||
*/ | |||
@Override | |||
protected void create(boolean stream) throws IOException { | |||
if (!stream) { | |||
throw new IllegalArgumentException("datagram socket creation not supported"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial thought was to just assert
the stream
value here. Then I noticed the test/jdk/java/net/SocketImpl/BadUsages.java
test (updated as part of this PR) and thought that it might be better to do an actual check here and have it throw IllegalArgumentException
, to allow for this behaviour to be verified.
I however don't have a strong opinion about this. So if assert
is enough, then I'll switch this to an assert and then remove the updated test method in the BasUsages.java
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can only throw IOException so I think it will need to throw IOException. It should happen of course, at least not unless we have a bug in the Socket code. Can you change the exception message to start with "Datagram socket ..." so it's consistent with the other exception messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - I've updated the PR to follow these suggestions. The BadUsages
test passes with this change.
@@ -82,8 +82,12 @@ public SocketImpl() { } | |||
* | |||
* @apiNote | |||
* The {@link Socket} constructors to create a datagram socket | |||
* are deprecated for removal. This method will be re-specified | |||
* in a future release to not support creating datagram sockets. | |||
* are deprecated for removal and have been respecified to throw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to talk about past, current and future behavior.
I thought we try to keep specifications focused on current behavior, with the exception of deprecation warnings.
Would it be possible to reword this without mentioning the past, avoiding the “have been respecified” part?
Interested users can always use release notes to observe history..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Eirik,
This seems to talk about past, current and future behavior.
...
Would it be possible to reword this without mentioning the past, avoiding the “have been respecified” part?
That's a good point. I've now updated the PR to reword this. Hopefully that's better.
* creates a datagram socket. | ||
* stream socket. Only stream socket creation is allowed. If the stream | ||
* argument is {@code false}, then this constructor throws | ||
* {@code IllegalArgumentException}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be tempted to drop this paragraph and just change the description of the @param stream
to say "must be true".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-read this paragraph again today and I think it would be better to remove it completely from both constructors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my previous round I misread that the review comment was on SocketImpl class, so I never did apply the review changes on these Socket
constructor.
I've now updated the PR to drop this paragraph from both these constructors. I'll update the CSR if this and the rest changes look good.
* this method. | ||
* <p> | ||
* This method will be re-specified in a future release to not | ||
* support creating datagram sockets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a change to take these suggestions. I did some minor changes to the wording. Do you recommend any further changes to that text?
I've created a CSR https://bugs.openjdk.org/browse/JDK-8356225 and is ready for review. |
* <p> | ||
* If the application has specified a {@linkplain SocketImplFactory client | ||
* socket implementation factory}, that factory's | ||
* {@linkplain SocketImplFactory#createSocketImpl() createSocketImpl} | ||
* method is called to create the actual socket implementation. Otherwise | ||
* a system-default socket implementation is created. | ||
* <p> | ||
* If a UDP socket is used, TCP/IP related socket options will not apply. | ||
* | ||
* @param host the host name, or {@code null} for the loopback address. | ||
* @param port the port number. | ||
* @param stream a {@code boolean} indicating whether this is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the parameter description has to be changed as it no longer indicates if the socket is a stream or datatgram socket. I think you can replace with something simple, like must be true, false is not allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* in a future release to not support creating datagram sockets. | ||
* The {@code stream} parameter provided a way in early JDK releases | ||
* to create a {@link Socket} that used a datagram socket. | ||
* It is no longer possible to do that and therefore this method will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"It is no longer possible to do that ...", can you try changing this to "The Socket API no longer provides a way to do this so the create method will ways to be called with a stream value of true". I think it might be a bit easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* If the stream argument is {@code true}, this creates a | ||
* stream socket. If the stream argument is {@code false}, it | ||
* creates a datagram socket. | ||
* <p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final though on the Socket changes is that maybe we should include an API note to say that the stream parameter provided a way in early JDK releases to create a Socket that used a datagram socket, this feature no longer exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spec + implementation changes looks fine, I have not spent time on the test changes.
* to create a {@code Socket} that used a datagram socket, this feature | ||
* no longer exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* to create a {@code Socket} that used a datagram socket, this feature | |
* no longer exists. | |
* to create a {@code Socket} that used a datagram socket. This feature | |
* no longer exists. |
* to create a {@code Socket} that used a datagram socket, this feature | ||
* no longer exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* to create a {@code Socket} that used a datagram socket, this feature | |
* no longer exists. | |
* to create a {@code Socket} that used a datagram socket. This feature | |
* no longer exists. |
@@ -454,6 +450,10 @@ private Socket(SocketAddress address, SocketAddress localAddr, boolean stream) | |||
throws IOException | |||
{ | |||
Objects.requireNonNull(address); | |||
if (!stream) { | |||
throw new IllegalArgumentException( | |||
"Socket constructor does not support creation of datagram socket"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Socket constructor does not support creation of datagram socket"); | |
"Socket constructor does not support creation of datagram sockets"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Michael, I updated the PR with all 3 suggestions. The CSR text too has been updated with this minor update.
* | ||
* @apiNote | ||
* The {@code stream} parameter provided a way in early JDK releases | ||
* to create a {@code Socket} that used a datagram socket. This feature | ||
* no longer exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also re-iterate here that this constructor is deprecated? It kind of feels like this information should be in @deprecated
instead, or that it should say that IAE is being thrown...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Daniel, do you mean something like this:
- * @apiNote
- * The {@code stream} parameter provided a way in early JDK releases
- * to create a {@code Socket} that used a datagram socket. This feature
- * no longer exists.
- *
* @param host the IP address.
* @param port the port number.
* @param stream must be true, false is not allowed.
@@ -429,7 +424,9 @@ public Socket(String host, int port, boolean stream) throws IOException {
* or if the port parameter is outside the specified range of valid
* port values, which is between 0 and 65535, inclusive.
* @throws NullPointerException if {@code host} is null.
- * @deprecated Use {@link DatagramSocket} instead for UDP transport.
+ * @deprecated The {@code stream} parameter provided a way in early JDK releases
+ * to create a {@code Socket} that used a datagram socket. This feature
+ * no longer exists. Use {@link DatagramSocket} instead for UDP transport.
Having that text in @deprecated
does convey the reason for deprecation and does show up prominently in the rendered javadoc:

So if you and others think we should remove the apiNote and move the text to deprecated, then I'll update the PR and the CSR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay with me but for SocketImpl then I think it has to be an apiNote as the create method is not deprecated.
BTW: "Use DatagramSocket instead for UDP transport" switches the terminology. The first sentence uses "datagram socket" so I best to use that in the second sentence to avoid "UDP" and "transport".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay with me but for SocketImpl then I think it has to be an apiNote as the create method is not deprecated.
Makes sense.
BTW: "Use DatagramSocket instead for UDP transport" switches the terminology. The first sentence uses "datagram socket" so I best to use that in the second sentence to avoid "UDP" and "transport".
I agree, I'll use "datagram socket".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jaikiran. Yes - it feels weird to add an @apiNote
to a method or constructor that has long been deprecated: if it's deprecated you're not supposed to use it. I couldn't help feeling that using an @apiNote
there conveyed the wrong message. I am completely OK with the @apiNote
on the create
method though - since that one isn't deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR to move the text into @deprecated
section for these 2 constructors. I'll update the CSR once this new text is approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I prefer the new version.
Thank you all for the reviews, the CSR has been approved with this latest text. I'll go ahead with the integration. |
/integrate |
Going to push as commit 52a5583.
Your commit was automatically rebased without conflicts. |
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 anIllegalArgumentException
when thestream
parameter isfalse
.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.
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25031/head:pull/25031
$ git checkout pull/25031
Update a local copy of the PR:
$ git checkout pull/25031
$ git pull https://git.openjdk.org/jdk.git pull/25031/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25031
View PR using the GUI difftool:
$ git pr show -t 25031
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25031.diff
Using Webrev
Link to Webrev Comment