Integrated: 8371091: Improve the exception message of NullPointerException thrown by the methods in the default implementation of HttpRequest.Builder
EunHyunsu
duke at openjdk.org
Thu Nov 6 16:16:55 UTC 2025
On Sun, 2 Nov 2025 07:19:12 GMT, EunHyunsu <duke at openjdk.org> wrote:
> 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.
This pull request has now been integrated.
Changeset: c272aca8
Author: EunHyunsu <ehs208 at naver.com>
Committer: Daniel Fuchs <dfuchs at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/c272aca8a0a2720365159684bed35c0c31e8778f
Stats: 41 lines in 2 files changed: 37 ins; 0 del; 4 mod
8371091: Improve the exception message of NullPointerException thrown by the methods in the default implementation of HttpRequest.Builder
Reviewed-by: dfuchs
-------------
PR: https://git.openjdk.org/jdk/pull/28103
More information about the net-dev
mailing list