From acfe562bcb5c0d703c23422cc78fef09a8c99f66 Mon Sep 17 00:00:00 2001 From: Nils Bandener Date: Tue, 28 Oct 2025 21:54:09 +0100 Subject: [PATCH] Made resolveIndices() in TransportSingleShardAction exception-safe Originally, the resolveIndices() method of TransportSingleShardAction was implemented with concreteSingleIndex(), which however can throw exceptions for validation issues. As throwing exceptions is not suitable for the intended meta-data use, this was moved to concreteResolvedIndices(). This MIGHT return a super-set of the indices of concreteSingleIndex() when the latter would throw an exception. This is for the intended purposes of resolveIndices() however acceptable. Signed-off-by: Nils Bandener --- .../single/shard/TransportSingleShardAction.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/opensearch/action/support/single/shard/TransportSingleShardAction.java b/server/src/main/java/org/opensearch/action/support/single/shard/TransportSingleShardAction.java index 329c542f39216..4c53e69575456 100644 --- a/server/src/main/java/org/opensearch/action/support/single/shard/TransportSingleShardAction.java +++ b/server/src/main/java/org/opensearch/action/support/single/shard/TransportSingleShardAction.java @@ -160,7 +160,17 @@ protected void resolveRequest(ClusterState state, InternalRequest request) { @Override public ResolvedIndices resolveIndices(Request request) { - return ResolvedIndices.ofNonNull(resolveToConcreteSingleIndex(request, clusterService.state())); + if (resolveIndex(request)) { + // We do not use resolveToConcreteSingleIndex() here because it might throw exceptions for validation errors. + // Instead, we use indexNameExpressionResolver.concreteResolvedIndices(), which allows us to retrieve + // index names without validation errors. This is potentially a super-set of the indices resolved in + // resolveToConcreteSingleIndex(), but this is only a hypothetical state. In practise, we should + // also always get one element here. If for some reason that's not the case, the code will hit the + // validation error when executing the action. + return ResolvedIndices.of(indexNameExpressionResolver.concreteResolvedIndices(clusterService.state(), request)); + } else { + return ResolvedIndices.of(request.index()); + } } private String resolveToConcreteSingleIndex(Request request, ClusterState clusterState) {