Skip to content

Conversation

@ehs208
Copy link
Contributor

@ehs208 ehs208 commented Nov 2, 2025

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8371091: Improve the exception message of NullPointerException thrown by the methods in the default implementation of HttpRequest.Builder (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28103/head:pull/28103
$ git checkout pull/28103

Update a local copy of the PR:
$ git checkout pull/28103
$ git pull https://git.openjdk.org/jdk.git pull/28103/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28103

View PR using the GUI difftool:
$ git pr show -t 28103

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28103.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 2, 2025

👋 Welcome back ehs208! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 2, 2025

@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:

8371091: Improve the exception message of NullPointerException thrown by the methods in the default implementation of HttpRequest.Builder

Reviewed-by: dfuchs

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 master branch:

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 /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the net net-dev@openjdk.org label Nov 2, 2025
@openjdk
Copy link

openjdk bot commented Nov 2, 2025

@ehs208 The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 2, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 2, 2025

Webrevs

@ehs208 ehs208 changed the title 8371091: Enhance npe message httprequest 8371091: Improve the exception message of NullPointerException thrown by the methods in the default implementation of HttpRequest.Builder Nov 2, 2025

@Override
public HttpRequest.Builder method(String method, BodyPublisher body) {
requireNonNull(method);
Copy link
Member

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.

Copy link
Contributor Author

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").

@jaikiran
Copy link
Member

jaikiran commented Nov 3, 2025

Hello @ehs208, instead of a new test class, could you see if the existing tests in test/jdk/java/net/httpclient/HttpRequestBuilderTest.java can be updated for additionally checking the NullPointerException message wherever applicable?

@ehs208
Copy link
Contributor Author

ehs208 commented Nov 3, 2025

Hello @ehs208, instead of a new test class, could you see if the existing tests in test/jdk/java/net/httpclient/HttpRequestBuilderTest.java can be updated for additionally checking the NullPointerException message wherever applicable?

Thanks for the suggestion! That makes sense — instead of keeping a separate test class,
I can move these checks into HttpRequestBuilderTest.java.

However, since the existing testNull() method focuses only on verifying that NPEs are thrown
(regardless of message content), would it make sense to add a small new test method,
say testNullMessages(), in the same class to verify the exception messages specifically?

That way we keep the tests co-located but with a clear separation of intent.

@jaikiran
Copy link
Member

jaikiran commented Nov 3, 2025

would it make sense to add a small new test method,
say testNullMessages(), in the same class to verify the exception messages specifically?

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.

@openjdk openjdk bot removed the rfr Pull request is ready for review label Nov 4, 2025
@ehs208
Copy link
Contributor Author

ehs208 commented Nov 4, 2025

would it make sense to add a small new test method,
say testNullMessages(), in the same class to verify the exception messages specifically?

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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 4, 2025
@ehs208 ehs208 requested a review from dfuch November 6, 2025 11:18
Copy link
Member

@dfuch dfuch left a 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!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 6, 2025
@ehs208
Copy link
Contributor Author

ehs208 commented Nov 6, 2025

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Nov 6, 2025
@openjdk
Copy link

openjdk bot commented Nov 6, 2025

@ehs208
Your change (at version f26cc33) is now ready to be sponsored by a Committer.

@dfuch
Copy link
Member

dfuch commented Nov 6, 2025

/sponsor

@openjdk
Copy link

openjdk bot commented Nov 6, 2025

Going to push as commit c272aca.
Since your change was applied there have been 88 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 6, 2025
@openjdk openjdk bot closed this Nov 6, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Nov 6, 2025
@openjdk
Copy link

openjdk bot commented Nov 6, 2025

@dfuch @ehs208 Pushed as commit c272aca.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated net net-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

3 participants