Skip to content

Commit cbb3bbd

Browse files
author
Christoph Büscher
authored
Prevent normalizer from not being closed on exception (#42375)
Currently AnalysisRegistry#processNormalizerFactory creates a normalizer and only later checks whether it should be added to the normalizer map passed in. In case we throw an exception it isn't closed. This can be prevented by moving the check that throws the exception earlier.
1 parent bd1dc98 commit cbb3bbd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,14 @@ private void processNormalizerFactory(
523523
if (normalizerFactory instanceof CustomNormalizerProvider) {
524524
((CustomNormalizerProvider) normalizerFactory).build(tokenizerName, tokenizerFactory, charFilters, tokenFilters);
525525
}
526+
if (normalizers.containsKey(name)) {
527+
throw new IllegalStateException("already registered analyzer with name: " + name);
528+
}
526529
Analyzer normalizerF = normalizerFactory.get();
527530
if (normalizerF == null) {
528531
throw new IllegalArgumentException("normalizer [" + normalizerFactory.name() + "] created null normalizer");
529532
}
530533
NamedAnalyzer normalizer = new NamedAnalyzer(name, normalizerFactory.scope(), normalizerF);
531-
if (normalizers.containsKey(name)) {
532-
throw new IllegalStateException("already registered analyzer with name: " + name);
533-
}
534534
normalizers.put(name, normalizer);
535535
}
536536
}

0 commit comments

Comments
 (0)