mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-25 06:16:40 +00:00
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.
This commit is contained in:
parent
6d8a0e36ec
commit
85ff9543b7
@ -526,14 +526,14 @@ public final class AnalysisRegistry implements Closeable {
|
||||
if (normalizerFactory instanceof CustomNormalizerProvider) {
|
||||
((CustomNormalizerProvider) normalizerFactory).build(tokenizerName, tokenizerFactory, charFilters, tokenFilters);
|
||||
}
|
||||
if (normalizers.containsKey(name)) {
|
||||
throw new IllegalStateException("already registered analyzer with name: " + name);
|
||||
}
|
||||
Analyzer normalizerF = normalizerFactory.get();
|
||||
if (normalizerF == null) {
|
||||
throw new IllegalArgumentException("normalizer [" + normalizerFactory.name() + "] created null normalizer");
|
||||
}
|
||||
NamedAnalyzer normalizer = new NamedAnalyzer(name, normalizerFactory.scope(), normalizerF);
|
||||
if (normalizers.containsKey(name)) {
|
||||
throw new IllegalStateException("already registered analyzer with name: " + name);
|
||||
}
|
||||
normalizers.put(name, normalizer);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user