From c9489606d5ae6ff3af6eac9f407260b3e1f4dca0 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 5 Nov 2020 15:09:31 +0100 Subject: [PATCH] HTTPCLIENT-2126: `AsyncCachingExec` throws NPE when response body is null --- .../apache/hc/client5/http/impl/cache/AsyncCachingExec.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java index c6db03c5d..2ccae5730 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java @@ -157,7 +157,9 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler cacheResponse, content != null ? new BasicEntityDetails(content.length, contentType) : null); if (dataConsumer != null) { - dataConsumer.consume(ByteBuffer.wrap(content)); + if (content != null) { + dataConsumer.consume(ByteBuffer.wrap(content)); + } dataConsumer.streamEnd(null); } asyncExecCallback.completed();