Skip to content

Commit 85ff954

Browse files
author
Christoph Büscher
committed
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 6d8a0e3 commit 85ff954

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
@@ -526,14 +526,14 @@ private void processNormalizerFactory(
526526
if (normalizerFactory instanceof CustomNormalizerProvider) {
527527
((CustomNormalizerProvider) normalizerFactory).build(tokenizerName, tokenizerFactory, charFilters, tokenFilters);
528528
}
529+
if (normalizers.containsKey(name)) {
530+
throw new IllegalStateException("already registered analyzer with name: " + name);
531+
}
529532
Analyzer normalizerF = normalizerFactory.get();
530533
if (normalizerF == null) {
531534
throw new IllegalArgumentException("normalizer [" + normalizerFactory.name() + "] created null normalizer");
532535
}
533536
NamedAnalyzer normalizer = new NamedAnalyzer(name, normalizerFactory.scope(), normalizerF);
534-
if (normalizers.containsKey(name)) {
535-
throw new IllegalStateException("already registered analyzer with name: " + name);
536-
}
537537
normalizers.put(name, normalizer);
538538
}
539539
}

0 commit comments

Comments
 (0)