From 72735be673b5ca0bff72944ccc2a61551cdf6af8 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 6 Jun 2019 14:04:45 +0200 Subject: [PATCH] Fix NPE when rejecting bulk updates (#42923) Single updates use a different internal code path than updates that are wrapped in a bulk request. While working on a refactoring to bring both closer together I've noticed that bulk updates were failing some of the tests that single updates passed. In particular, bulk updates cause NullPointerExceptions to be thrown and listeners not being properly notified when being rejected from the thread pool. --- .../action/bulk/TransportShardBulkAction.java | 3 +-- .../java/org/elasticsearch/update/UpdateIT.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java index 372923c9036..ad803589f9d 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -342,11 +342,10 @@ public class TransportShardBulkAction extends TransportWriteAction { + final BulkItemResponse ir = br.getItems()[0]; + if (ir.isFailed()) { + throw ir.getFailure().getCause(); + } else { + return ir.getResponse(); + } + })); + } } catch (NoNodeAvailableException nne) { updateRequestsOutstanding.release(); synchronized (failedMap) {