From 9317b0a48cbca3e3414a6329a347b82c63a6c242 Mon Sep 17 00:00:00 2001 From: "Kirill A. Korinsky" Date: Wed, 6 Jul 2022 23:40:18 +0200 Subject: [PATCH] Fixed NullPointerException on bulk request Java's `ArrayList.toArray()` returns provided array when collection is empty. Here is created a one-element array which contains null element. Thus, returned `BulkResponse` may contains a null element as `BulkItemResponse`. How to achieve: 1. Sent a request to `/_bulk?filter_path=took,errors` 2. call inside `BulkProcessor.Listener` a `BulkResponse.hasFailures()` --- server/src/main/java/org/elasticsearch/action/bulk/Retry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/action/bulk/Retry.java b/server/src/main/java/org/elasticsearch/action/bulk/Retry.java index 99864c509b51f..207b810d5422f 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/Retry.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/Retry.java @@ -195,7 +195,7 @@ private void addResponses(BulkResponse response, Predicate fil private BulkResponse getAccumulatedResponse() { BulkItemResponse[] itemResponses; synchronized (responses) { - itemResponses = responses.toArray(new BulkItemResponse[1]); + itemResponses = responses.toArray(new BulkItemResponse[0]); } long stopTimestamp = System.nanoTime(); long totalLatencyMs = TimeValue.timeValueNanos(stopTimestamp - startTimestampNanos).millis();