@@ -427,22 +427,6 @@ Index[] concreteIndices(Context context, String... indexExpressions) {
427427 return concreteIndices .toArray (Index .EMPTY_ARRAY );
428428 }
429429
430- private IndexNotFoundException notFoundException (String ... indexExpressions ) {
431- IndexNotFoundException infe ;
432- if (indexExpressions .length == 1 ) {
433- if (indexExpressions [0 ].equals (Metadata .ALL )) {
434- infe = new IndexNotFoundException ("no indices exist" , indexExpressions [0 ]);
435- } else {
436- infe = new IndexNotFoundException (indexExpressions [0 ]);
437- }
438- infe .setResources ("index_expression" , indexExpressions [0 ]);
439- } else {
440- infe = new IndexNotFoundException ((String ) null );
441- infe .setResources ("index_expression" , indexExpressions );
442- }
443- return infe ;
444- }
445-
446430 private void checkSystemIndexAccess (Context context , Set <Index > concreteIndices ) {
447431 final Metadata metadata = context .getState ().metadata ();
448432 final Predicate <String > systemIndexAccessPredicate = context .getSystemIndexAccessPredicate ().negate ();
@@ -489,6 +473,22 @@ private void checkSystemIndexAccess(Context context, Set<Index> concreteIndices)
489473 }
490474 }
491475
476+ private static IndexNotFoundException notFoundException (String ... indexExpressions ) {
477+ IndexNotFoundException infe ;
478+ if (indexExpressions != null && indexExpressions .length == 1 ) {
479+ if (Metadata .ALL .equals (indexExpressions [0 ])) {
480+ infe = new IndexNotFoundException ("no indices exist" , indexExpressions [0 ]);
481+ } else {
482+ infe = new IndexNotFoundException (indexExpressions [0 ]);
483+ }
484+ infe .setResources ("index_or_alias" , indexExpressions [0 ]);
485+ } else {
486+ infe = new IndexNotFoundException ((String ) null );
487+ infe .setResources ("index_expression" , indexExpressions );
488+ }
489+ return infe ;
490+ }
491+
492492 private static boolean shouldTrackConcreteIndex (Context context , IndicesOptions options , Index index ) {
493493 if (context .systemIndexAccessLevel == SystemIndexAccessLevel .BACKWARDS_COMPATIBLE_ONLY
494494 && context .netNewSystemIndexPredicate .test (index .getName ())) {
@@ -1216,7 +1216,7 @@ private static Collection<String> innerResolve(Context context, List<String> exp
12161216 matchingOpenClosedNames .forEachOrdered (result ::add );
12171217 }
12181218 if (emptyWildcardExpansion .get ()) {
1219- throw indexNotFoundException (expression );
1219+ throw notFoundException (expression );
12201220 }
12211221 } else {
12221222 if (isExclusion ) {
@@ -1248,7 +1248,7 @@ private static Collection<String> innerResolve(Context context, List<String> exp
12481248
12491249 private static String validateAliasOrIndex (String expression ) {
12501250 if (Strings .isEmpty (expression )) {
1251- throw indexNotFoundException (expression );
1251+ throw notFoundException (expression );
12521252 }
12531253 // Expressions can not start with an underscore. This is reserved for APIs. If the check gets here, the API
12541254 // does not exist and the path is interpreted as an expression. If the expression begins with an underscore,
@@ -1265,23 +1265,17 @@ private static void ensureAliasOrIndexExists(Context context, String expression)
12651265 final IndicesOptions options = context .getOptions ();
12661266 IndexAbstraction indexAbstraction = context .getState ().getMetadata ().getIndicesLookup ().get (expression );
12671267 if (indexAbstraction == null ) {
1268- throw indexNotFoundException (expression );
1268+ throw notFoundException (expression );
12691269 }
12701270 // treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api)
12711271 if (indexAbstraction .getType () == Type .ALIAS && options .ignoreAliases ()) {
12721272 throw aliasesNotSupportedException (expression );
12731273 }
12741274 if (indexAbstraction .isDataStreamRelated () && context .includeDataStreams () == false ) {
1275- throw indexNotFoundException (expression );
1275+ throw notFoundException (expression );
12761276 }
12771277 }
12781278
1279- private static IndexNotFoundException indexNotFoundException (String expression ) {
1280- IndexNotFoundException infe = new IndexNotFoundException (expression );
1281- infe .setResources ("index_or_alias" , expression );
1282- return infe ;
1283- }
1284-
12851279 private static IndexMetadata .State excludeState (IndicesOptions options ) {
12861280 final IndexMetadata .State excludeState ;
12871281 if (options .expandWildcardsOpen () && options .expandWildcardsClosed ()) {
0 commit comments