-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8371091: Improve the exception message of NullPointerException thrown by the methods in the default implementation of HttpRequest.Builder #28103
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
…ublisher in HttpRequest.Builder methods
…dyPublisher in HttpRequest.Builder
|
👋 Welcome back ehs208! A progress list of the required criteria for merging this PR into |
|
@ehs208 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 86 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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@dfuch) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
Webrevs
|
|
|
||
| @Override | ||
| public HttpRequest.Builder method(String method, BodyPublisher body) { | ||
| requireNonNull(method); |
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 seems strange to improve the message for body but not for method.
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 agree for consistency.
I'll update the requireNonNull(method) call to include an explicit message as well, e.g.,
requireNonNull(method, "HTTP method must be non-null").
|
Hello @ehs208, instead of a new test class, could you see if the existing tests in |
Thanks for the suggestion! That makes sense — instead of keeping a separate test class, However, since the existing That way we keep the tests co-located but with a clear separation of intent. |
I think that should be OK. It doesn't have to be too complicated/generic either, as long as it tests these specific method calls. |
Thanks for confirming! I’ll add a straightforward testNullMessages() method in the same class to verify those specific calls. |
dfuch
left a comment
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 ran HttpClient tests in the CI and they came back green.
So look good to me!
|
/integrate |
|
/sponsor |
|
Going to push as commit c272aca.
Your commit was automatically rebased without conflicts. |
This change adds clearer NullPointerException messages to the POST(), PUT(), and method() methods in HttpRequest.Builder when the provided BodyPublisher is null.
Each of these methods now calls
requireNonNull(body, "BodyPublisher must not be null"), making the exception message explicit.A corresponding regression test (RequestBuilderNullBodyTest) has been added to verify this behavior.
All builds and related tests (jdk/java/net/httpclient) have passed successfully.
Currently, only POST(), PUT(), and method() include these messages.
Some other builder methods (such as header(), setHeader()) also throw NullPointerException without a message.
I would like to discuss whether adding consistent messages to those methods would be beneficial,
and whether the current wording "BodyPublisher must not be null" feels appropriate.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28103/head:pull/28103$ git checkout pull/28103Update a local copy of the PR:
$ git checkout pull/28103$ git pull https://git.openjdk.org/jdk.git pull/28103/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28103View PR using the GUI difftool:
$ git pr show -t 28103Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28103.diff
Using Webrev
Link to Webrev Comment