Skip to content

NullPointerException when HttpResponse.body() is null #1222

@tpetillot

Description

@tpetillot

Description

When using the http4s JDK HTTP client, a NullPointerException is thrown if the HttpResponse.body() is null.

This can occur, for example, when a proxy returns 407 Proxy Authentication Required.

Reference:
org/http4s/jdkhttpclient/JdkHttpClient.scala#L196

Stacktrace:

java.lang.NullPointerException: Cannot invoke "java.util.concurrent.Flow$Publisher.subscribe(java.util.concurrent.Flow$Subscriber)" because the return value of "java.net.http.HttpResponse.body()" is null
    at org.http4s.jdkhttpclient.JdkHttpClient$.$anonfun$apply$9(JdkHttpClient.scala:196)
    at delay @ org.http4s.jdkhttpclient.JdkHttpClient$.$anonfun$apply$8(JdkHttpClient.scala:196)
    at tryGet @ org.http4s.jdkhttpclient.JdkHttpClient$.$anonfun$apply$7(JdkHttpClient.scala:183)
    at flatMap @ org.http4s.jdkhttpclient.JdkHttpClient$.$anonfun$apply$7(JdkHttpClient.scala:183)
    ...
    at parallel @ fs2.interop.flow.StreamPublisher$.apply(StreamPublisher.scala:92)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions