Forráskód Böngészése

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.
Christoph Büscher 6 éve
szülő
commit
cbb3bbdd78

+ 3 - 3
server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java

@@ -523,14 +523,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);
     }
 }