http4s-jdk-http-client icon indicating copy to clipboard operation
http4s-jdk-http-client copied to clipboard

`NullPointerException` when `HttpResponse.body()` is `null`

Open tpetillot opened this issue 6 months ago • 0 comments

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)

tpetillot avatar Oct 21 '25 15:10 tpetillot