Skip to content

Commit c5d4c57

Browse files
committed
Fixed StringIndexOutOfBoundsException caused by empty index expression strings
Signed-off-by: Nils Bandener <nils.bandener@eliatra.com>
1 parent cb9c30b commit c5d4c57

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

server/src/main/java/org/opensearch/cluster/metadata/IndexNameExpressionResolver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,7 @@ private Set<String> innerResolve(Context context, List<String> expressions, Indi
11111111
String expression = expressions.get(i);
11121112
if (Strings.isEmpty(expression)) {
11131113
context.addResolutionError(indexNotFoundException(expression));
1114+
continue;
11141115
}
11151116
validateAliasOrIndex(context, expression);
11161117
if (aliasOrIndexExists(context, options, metadata, expression)) {

server/src/test/java/org/opensearch/cluster/metadata/IndexNameExpressionResolverTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,22 @@ public void testInvalidIndex() {
21122112
assertEquals("Invalid index name [_foo], must not start with '_'.", iine.getMessage());
21132113
}
21142114

2115+
public void testInvalidEmptyIndex() {
2116+
Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test"));
2117+
ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
2118+
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(
2119+
state,
2120+
IndicesOptions.lenientExpandOpen(),
2121+
false
2122+
);
2123+
2124+
IndexNotFoundException indexNotFoundException = expectThrows(
2125+
IndexNotFoundException.class,
2126+
() -> indexNameExpressionResolver.concreteIndexNames(context, "")
2127+
);
2128+
assertEquals("no such index []", indexNotFoundException.getMessage());
2129+
}
2130+
21152131
public void testIgnoreThrottled() {
21162132
Metadata.Builder mdBuilder = Metadata.builder()
21172133
.put(

0 commit comments

Comments
 (0)