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

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: None
    • Component/s: core-libs

      Some methods on java.net.http.HttpRequest.Builder, like the POST(), PUT() and method() accept a BodyPublisher. These methods throw a NullPointerException when the given BodyPublisher is null. The default implementation of the HttpRequest.Builder in the JDK throws a NullPointerException of the form:

      Exception in thread "main" java.lang.NullPointerException
        at java.base/java.util.Objects.requireNonNull(Objects.java:220)
        at java.net.http/jdk.internal.net.http.HttpRequestBuilderImpl.POST(HttpRequestBuilderImpl.java:180)

      It would be good to include what is null in the exception message of that NullPointerException.

      This was brought up in the net-dev mailing list discussion https://mail.openjdk.org/pipermail/net-dev/2025-November/028733.html

            Assignee:
            Unassigned
            Reporter:
            Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: