diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/PerFieldAnalyzerWrapper.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/PerFieldAnalyzerWrapper.java index 2d9b1da15574..01a74728420e 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/PerFieldAnalyzerWrapper.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/PerFieldAnalyzerWrapper.java @@ -88,4 +88,11 @@ protected Analyzer getWrappedAnalyzer(String fieldName) { public String toString() { return "PerFieldAnalyzerWrapper(" + fieldAnalyzers + ", default=" + defaultAnalyzer + ")"; } + + @Override + public void close() { + defaultAnalyzer.close(); + fieldAnalyzers.values().forEach(Analyzer::close); + super.close(); + } } diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestPerFieldAnalyzerWrapper.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestPerFieldAnalyzerWrapper.java index 903076d68fd6..d710b2c16535 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestPerFieldAnalyzerWrapper.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestPerFieldAnalyzerWrapper.java @@ -68,10 +68,7 @@ public void testPerField() throws Exception { assertFalse(tokenStream.incrementToken()); tokenStream.end(); } - // TODO: fix this about PFAW, this is crazy analyzer.close(); - defaultAnalyzer.close(); - IOUtils.close(analyzerPerField.values()); } public void testReuseWrapped() throws Exception { @@ -125,7 +122,7 @@ protected TokenStreamComponents wrapComponents(String fieldName, TokenStreamComp ts4 = wrapper3.tokenStream("moreSpecial", text); assertSame(ts3, ts4); assertSame(ts2, ts3); - IOUtils.close(wrapper3, wrapper2, wrapper1, specialAnalyzer, defaultAnalyzer); + IOUtils.close(wrapper3, wrapper2, wrapper1); } public void testCharFilters() throws Exception { @@ -155,6 +152,5 @@ protected Reader initReader(String fieldName, Reader reader) { new int[] { 2 } ); p.close(); - a.close(); // TODO: fix this about PFAW, its a trap } }