Skip to content

Commit 5c13399

Browse files
committed
Fix NPE in rolling over unknown target
Since #122905 we were throwing NPEs (i.e. 5xxs) when a rollover request has an unknown/non-existent target. This PR restores that to it's original behavior (which is to return a 400 - illegal argument exception). Additionally, to avoid this from happening again, we add a YAML test that asserts the correct exception behavior.
1 parent e9c4b26 commit 5c13399

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.rollover/10_basic.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,11 @@
183183
min_age: "0s"
184184
min_docs: 1
185185
- match: { error.reason: "Validation Failed: 1: at least one max_* rollover condition must be set when using min_* conditions;" }
186+
187+
---
188+
"Rolling over an unknown target should return 404":
189+
- do:
190+
catch: bad_request
191+
indices.rollover:
192+
alias: "non_existent"
193+
- match: {error.reason: "rollover target [non_existent] does not exist"}

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected ClusterBlockException checkBlock(RolloverRequest request, ClusterState
164164
ResolvedExpression resolvedRolloverTarget = SelectorResolver.parseExpression(request.getRolloverTarget(), request.indicesOptions());
165165
final IndexAbstraction indexAbstraction = projectMetadata.getIndicesLookup().get(resolvedRolloverTarget.resource());
166166
final String[] indicesToCheck;
167-
if (indexAbstraction.getType().equals(IndexAbstraction.Type.DATA_STREAM)) {
167+
if (indexAbstraction != null && indexAbstraction.getType().equals(IndexAbstraction.Type.DATA_STREAM)) {
168168
DataStream dataStream = (DataStream) indexAbstraction;
169169
boolean targetFailureStore = resolvedRolloverTarget.selector() != null
170170
&& resolvedRolloverTarget.selector().shouldIncludeFailures();

0 commit comments

Comments
 (0)