Skip to content

Commit c1f569a

Browse files
committed
Check that iterator is not empty
1 parent b70c57b commit c1f569a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlExecutionInfo.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,15 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
295295

296296
private Iterator<? extends ToXContent> onlyFailuresToXContent() {
297297
Iterator<Cluster> failuresIterator = clusterInfo.values().stream().filter(c -> (c.getFailures().isEmpty() == false)).iterator();
298-
return Iterators.concat(
299-
ChunkedToXContentHelper.startObject(),
300-
ChunkedToXContentHelper.object("details", failuresIterator),
301-
ChunkedToXContentHelper.endObject()
302-
);
298+
if (failuresIterator.hasNext()) {
299+
return Iterators.concat(
300+
ChunkedToXContentHelper.startObject(),
301+
ChunkedToXContentHelper.object("details", failuresIterator),
302+
ChunkedToXContentHelper.endObject()
303+
);
304+
} else {
305+
return Collections.emptyIterator();
306+
}
303307
}
304308

305309
/**

0 commit comments

Comments
 (0)