Skip to content

Commit

Permalink
Prevent memory leaks in PerFieldAnalyzerWrapper
Browse files Browse the repository at this point in the history
By overriding the 'close' method. Otherwise nothing will close the
defaultAnalyzer as well as all the fieldAnalyzers.
  • Loading branch information
boris-petrov committed Dec 6, 2018
1 parent b4e1fe4 commit 5f8d074
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -127,7 +124,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 {
Expand Down Expand Up @@ -157,6 +154,5 @@ protected Reader initReader(String fieldName, Reader reader) {
new int[] { 2 }
);
p.close();
a.close(); // TODO: fix this about PFAW, its a trap
}
}

0 comments on commit 5f8d074

Please sign in to comment.