This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ad5795  Ensure Lucene's ByteBuffersDirectory is closed after use 
(#4884)
8ad5795 is described below

commit 8ad5795d9ea0eae7cbc565cb847853c55e0a848b
Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com>
AuthorDate: Thu Jan 14 16:05:58 2021 +0100

    Ensure Lucene's ByteBuffersDirectory is closed after use (#4884)
---
 .../apache/camel/catalog/lucene/LuceneSuggestionStrategy.java    | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git 
a/catalog/camel-catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java
 
b/catalog/camel-catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java
index 29fc151..06911ad 100644
--- 
a/catalog/camel-catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java
+++ 
b/catalog/camel-catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java
@@ -50,11 +50,12 @@ public class LuceneSuggestionStrategy implements 
SuggestionStrategy {
             PlainTextDictionary words = new PlainTextDictionary(reader);
 
             // use in-memory lucene spell checker to make the suggestions
-            ByteBuffersDirectory dir = new ByteBuffersDirectory();
-            checker = new SpellChecker(dir);
-            checker.indexDictionary(words, new IndexWriterConfig(new 
KeywordAnalyzer()), false);
+            try (ByteBuffersDirectory dir = new ByteBuffersDirectory()) {
+                checker = new SpellChecker(dir);
+                checker.indexDictionary(words, new IndexWriterConfig(new 
KeywordAnalyzer()), false);
 
-            return checker.suggestSimilar(unknownOption, maxSuggestions);
+                return checker.suggestSimilar(unknownOption, maxSuggestions);
+            }
         } catch (Exception e) {
             // ignore
         }

Reply via email to