You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2016/10/02 14:35:51 UTC
[33/50] [abbrv] lucenenet git commit: Suggest.Spell.SpellChecker: Per
MSDN, calling Dispose() multiple times should be a safe operation,
so fixed the behavior to allow it and changed the test.
https://msdn.microsoft.com/en-us/library/system.idisposable.d
Suggest.Spell.SpellChecker: Per MSDN, calling Dispose() multiple times should be a safe operation, so fixed the behavior to allow it and changed the test. https://msdn.microsoft.com/en-us/library/system.idisposable.dispose.aspx
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/432dec90
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/432dec90
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/432dec90
Branch: refs/heads/master
Commit: 432dec909bc2d18e78d0255232d4a45cd3007a68
Parents: 183ae70
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sun Sep 18 23:49:49 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Sun Oct 2 17:44:56 2016 +0700
----------------------------------------------------------------------
src/Lucene.Net.Suggest/Spell/SpellChecker.cs | 15 ++++++-------
.../Spell/TestSpellChecker.cs | 22 ++++++++++++--------
2 files changed, 21 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/432dec90/src/Lucene.Net.Suggest/Spell/SpellChecker.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Suggest/Spell/SpellChecker.cs b/src/Lucene.Net.Suggest/Spell/SpellChecker.cs
index 3ab001b..b7b534e 100644
--- a/src/Lucene.Net.Suggest/Spell/SpellChecker.cs
+++ b/src/Lucene.Net.Suggest/Spell/SpellChecker.cs
@@ -499,7 +499,6 @@ namespace Lucene.Net.Search.Spell
/// <param name="fullMerge"> whether or not the spellcheck index should be fully merged </param>
/// <exception cref="AlreadyClosedException"> if the <see cref="Spellchecker"/> is already disposed </exception>
/// <exception cref="System.IO.IOException"> If there is a low-level I/O error. </exception>
- // LUCENENET TODO: Replace all usage of AlreadyClosedException with System.ObjectDisposedException
public void IndexDictionary(IDictionary dict, IndexWriterConfig config, bool fullMerge)
{
lock (modifyCurrentIndexLock)
@@ -678,15 +677,17 @@ namespace Lucene.Net.Search.Spell
/// <exception cref="AlreadyClosedException"> if the <see cref="SpellChecker"/> is already disposed </exception>
public void Dispose()
{
- lock (searcherLock)
+ if (!disposed)
{
- EnsureOpen();
- disposed = true;
- if (searcher != null)
+ lock (searcherLock)
{
- searcher.IndexReader.Dispose();
+ disposed = true;
+ if (searcher != null)
+ {
+ searcher.IndexReader.Dispose();
+ }
+ searcher = null;
}
- searcher = null;
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/432dec90/src/Lucene.Net.Tests.Suggest/Spell/TestSpellChecker.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Suggest/Spell/TestSpellChecker.cs b/src/Lucene.Net.Tests.Suggest/Spell/TestSpellChecker.cs
index 48385b4..5909ca8 100644
--- a/src/Lucene.Net.Tests.Suggest/Spell/TestSpellChecker.cs
+++ b/src/Lucene.Net.Tests.Suggest/Spell/TestSpellChecker.cs
@@ -402,15 +402,19 @@ namespace Lucene.Net.Search.Spell
AssertLastSearcherOpen(4);
spellChecker.Dispose();
AssertSearchersClosed();
- try
- {
- spellChecker.Dispose();
- fail("spellchecker was already closed");
- }
- catch (AlreadyClosedException e)
- {
- // expected
- }
+ // LUCENENET NOTE: Per MSDN, calling Dispose() multiple times
+ // should be a safe operation. http://stackoverflow.com/a/5306896/181087
+ // Certainly, there shouldn't be a problem with calling Dispose() within
+ // a using block if you decide to free up resources early.
+ //try
+ //{
+ // spellChecker.Dispose();
+ // fail("spellchecker was already closed");
+ //}
+ //catch (AlreadyClosedException e)
+ //{
+ // // expected
+ //}
try
{
CheckCommonSuggestions(r);