Skip to content

java.lang.NullPointerException: flowPublisher in HttpClientZioBackend when proxy requires authentication #1697

@aleksandr-vin

Description

@aleksandr-vin

If proxy requires authentication (replies with 407 status), then NPE arises.

The stack trace:

[info] java.lang.NullPointerException: flowPublisher
[info] 	at java.base/java.util.Objects.requireNonNull(Objects.java:246)
[info] 	at org.reactivestreams.FlowAdapters.toPublisher(FlowAdapters.java:28)
[info] 	at sttp.client3.httpclient.zio.HttpClientZioBackend.publisherToBody(HttpClientZioBackend.scala:49)
[info] 	at sttp.client3.httpclient.zio.HttpClientZioBackend.publisherToBody(HttpClientZioBackend.scala:26)
[info] 	at sttp.client3.HttpClientAsyncBackend.$anonfun$sendRegular$3(HttpClientAsyncBackend.scala:51)
[info] 	at sttp.client3.HttpClientAsyncBackend.$anonfun$sendRegular$3$adapted(HttpClientAsyncBackend.scala:49)
[info] 	at sttp.client3.internal.SttpToJavaConverters$$anon$2.accept(SttpToJavaConverters.scala:12)
[info] 	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
[info] 	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
[info] 	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
[info] 	at java.base/java.util.concurrent.CompletableFuture.postFire(CompletableFuture.java:610)
[info] 	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:840)
[info] 	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
[info] 	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
[info] 	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
[info] 	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
[info] 	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
[info] 	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

For:

val httpClient = HttpClient
      .newBuilder()
      .followRedirects(HttpClient.Redirect.NEVER)
      .connectTimeout(Duration.ofSeconds(timeout.toSeconds))
      .proxy(ProxySelector.of(new InetSocketAddress(proxyConfig.host, proxyConfig.port)))
      .build()

val backend = HttpClientZioBackend.usingClient(httpClient)
...
response <- backend.send(request.response(asJsonAlways[A]))

Same if proxy configured following the example https://sttp.softwaremill.com/en/latest/conf/proxy.html?highlight=proxy:

SttpBackendOptions.httpProxy(proxyConfig.host, proxyConfig.port)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions