diff --git a/core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java b/core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java index 3582f5f5aaf..6cc063d5af1 100644 --- a/core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java @@ -106,17 +106,18 @@ public abstract class TransportNodesAction responses = new ArrayList<>(); final List failures = new ArrayList<>(); + final boolean accumulateExceptions = accumulateExceptions(); for (int i = 0; i < nodesResponses.length(); ++i) { Object response = nodesResponses.get(i); - if (nodeResponseClass.isInstance(response)) { - responses.add(nodeResponseClass.cast(response)); - } else if (response instanceof FailedNodeException) { - failures.add((FailedNodeException)response); + if (response instanceof FailedNodeException) { + if (accumulateExceptions) { + failures.add((FailedNodeException)response); + } else { + logger.warn("not accumulating exceptions, excluding exception from response", (FailedNodeException)response); + } } else { - logger.warn("ignoring unexpected response [{}] of type [{}], expected [{}] or [{}]", - response, response != null ? response.getClass().getName() : null, - nodeResponseClass.getSimpleName(), FailedNodeException.class.getSimpleName()); + responses.add(nodeResponseClass.cast(response)); } } @@ -243,9 +244,7 @@ public abstract class TransportNodesAction) () -> new ParameterizedMessage("failed to execute on node [{}]", nodeId), t); } - if (accumulateExceptions()) { - responses.set(idx, new FailedNodeException(nodeId, "Failed node [" + nodeId + "]", t)); - } + responses.set(idx, new FailedNodeException(nodeId, "Failed node [" + nodeId + "]", t)); if (counter.incrementAndGet() == responses.length()) { finishHim(); }