diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs index cc85abe77c..67f22a9591 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 namespace Lucene.Net.Analysis.Miscellaneous { /* @@ -96,6 +96,7 @@ protected override void Dispose(bool disposing) { suffix.Dispose(); } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } public override void End() diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs index 58ca6ff64f..118f67b03e 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs @@ -1,4 +1,4 @@ -// Lucene version compatibility level 4.8.1 +// Lucene version compatibility level 4.8.1 using Lucene.Net.Analysis.TokenAttributes; using Lucene.Net.Util; @@ -182,6 +182,7 @@ protected override void Dispose(bool disposing) prefix.Dispose(); suffix.Dispose(); } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } public override void Reset() diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs index cc6ecb33e2..8bf2ee334c 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs @@ -138,6 +138,7 @@ protected override void Dispose(bool disposing) this.isDisposing = false; #endif } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } /// diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/NearRealtimeReaderTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/NearRealtimeReaderTask.cs index df2824ec50..f4b5178b07 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Tasks/NearRealtimeReaderTask.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/NearRealtimeReaderTask.cs @@ -123,6 +123,7 @@ protected override void Dispose(bool disposing) } Console.WriteLine(); } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } public override bool SupportsParams => true; diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs index 608a03512d..698234c658 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs @@ -76,6 +76,7 @@ protected override void Dispose(bool disposing) } RunData.DocMaker.Dispose(); } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } private void InitTasksArray() diff --git a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs index df4a646220..e51dc16d38 100644 --- a/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs +++ b/src/Lucene.Net.Codecs/Memory/MemoryDocValuesConsumer.cs @@ -499,8 +499,17 @@ private void EncodeValues(int count) public void Dispose() { - this.counts.Dispose(); - this.ords.Dispose(); + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + this.counts.Dispose(); + this.ords.Dispose(); + } } // LUCENENET: Remove() not supported in .NET diff --git a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs index 630abf80e9..c466b89a7a 100644 --- a/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs +++ b/src/Lucene.Net.Facet/Taxonomy/WriterCache/CollisionMap.cs @@ -213,7 +213,7 @@ internal virtual int GetMemoryUsage() return memoryUsage; } - private class EntryEnumerator : IEnumerator + private sealed class EntryEnumerator : IEnumerator // LUCENENET: Marked sealed { internal Entry next; // next entry to return internal int index; // current slot diff --git a/src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs b/src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs index 4f2a53adb8..534273dffb 100644 --- a/src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs +++ b/src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs @@ -367,7 +367,7 @@ protected internal virtual void Scan(int scanDetailLevel) /// /// Used for . /// - private class VNodeCellEnumerator : IEnumerator + private sealed class VNodeCellEnumerator : IEnumerator// LUCENENET: Marked sealed { internal readonly IEnumerator cellIter; private readonly VNode vNode; diff --git a/src/Lucene.Net/Analysis/TokenFilter.cs b/src/Lucene.Net/Analysis/TokenFilter.cs index 400a6ddf84..fc5630a943 100644 --- a/src/Lucene.Net/Analysis/TokenFilter.cs +++ b/src/Lucene.Net/Analysis/TokenFilter.cs @@ -82,6 +82,7 @@ protected override void Dispose(bool disposing) { m_input.Dispose(); } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } /// diff --git a/src/Lucene.Net/Analysis/Tokenizer.cs b/src/Lucene.Net/Analysis/Tokenizer.cs index fc49d48710..4fa95e0172 100644 --- a/src/Lucene.Net/Analysis/Tokenizer.cs +++ b/src/Lucene.Net/Analysis/Tokenizer.cs @@ -79,6 +79,7 @@ protected override void Dispose(bool disposing) inputPending = ILLEGAL_STATE_READER; m_input = ILLEGAL_STATE_READER; } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } /// diff --git a/src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs b/src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs index 40faa73c7e..82799e38b6 100644 --- a/src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs +++ b/src/Lucene.Net/Codecs/PerField/PerFieldDocValuesFormat.cs @@ -1,4 +1,4 @@ -using J2N.Runtime.CompilerServices; +using J2N.Runtime.CompilerServices; using Lucene.Net.Diagnostics; using System; using System.Collections.Generic; @@ -94,7 +94,16 @@ internal class ConsumerAndSuffix : IDisposable public void Dispose() { - Consumer.Dispose(); + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + Consumer.Dispose(); + } } } diff --git a/src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs b/src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs index 37ea7c32a9..2738edcb68 100644 --- a/src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs +++ b/src/Lucene.Net/Codecs/PerField/PerFieldPostingsFormat.cs @@ -89,7 +89,16 @@ internal class FieldsConsumerAndSuffix : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { - Consumer.Dispose(); + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + Consumer.Dispose(); + } } } diff --git a/src/Lucene.Net/Index/IndexWriter.cs b/src/Lucene.Net/Index/IndexWriter.cs index 70e7352417..48b2b45b92 100644 --- a/src/Lucene.Net/Index/IndexWriter.cs +++ b/src/Lucene.Net/Index/IndexWriter.cs @@ -594,7 +594,16 @@ public virtual void Release(ReadersAndUpdates rld, bool assertInfoLive) public void Dispose() { - DropAll(false); + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + DropAll(false); + } } /// diff --git a/src/Lucene.Net/Index/PrefixCodedTerms.cs b/src/Lucene.Net/Index/PrefixCodedTerms.cs index 4c1090a1f5..c4b4ec6e88 100644 --- a/src/Lucene.Net/Index/PrefixCodedTerms.cs +++ b/src/Lucene.Net/Index/PrefixCodedTerms.cs @@ -87,7 +87,7 @@ internal PrefixCodedTermsIterator(RAMFile buffer) public void Dispose() { Dispose(true); - GC.SuppressFinalize(true); + GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) diff --git a/src/Lucene.Net/Store/FSDirectory.cs b/src/Lucene.Net/Store/FSDirectory.cs index 6471023c95..fee4ffe414 100644 --- a/src/Lucene.Net/Store/FSDirectory.cs +++ b/src/Lucene.Net/Store/FSDirectory.cs @@ -562,6 +562,7 @@ protected override void Dispose(bool disposing) } } } + //base.Dispose(disposing); // LUCENENET: No need to call base class, we are not using the functionality of BufferedIndexOutput } /// diff --git a/src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs b/src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs index 3cc52bbb9a..29fae0a5d9 100644 --- a/src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs +++ b/src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs @@ -358,6 +358,7 @@ protected override void Dispose(bool disposing) { textWriter.Dispose(); } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } } } diff --git a/src/Lucene.Net/Support/Index/TaskMergeScheduler.cs b/src/Lucene.Net/Support/Index/TaskMergeScheduler.cs index ec93e9a17d..9845937085 100644 --- a/src/Lucene.Net/Support/Index/TaskMergeScheduler.cs +++ b/src/Lucene.Net/Support/Index/TaskMergeScheduler.cs @@ -621,14 +621,23 @@ private void Run(CancellationToken cancellationToken) public void Dispose() { - if (_isDisposed) + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) { - return; - } + if (_isDisposed) + { + return; + } - _isDisposed = true; - _lock.Dispose(); - _cancellationTokenSource.Dispose(); + _isDisposed = true; + _lock.Dispose(); + _cancellationTokenSource.Dispose(); + } } public override string ToString() diff --git a/src/Lucene.Net/Util/PrintStreamInfoStream.cs b/src/Lucene.Net/Util/PrintStreamInfoStream.cs index fb1a1b4b96..451586e7f6 100644 --- a/src/Lucene.Net/Util/PrintStreamInfoStream.cs +++ b/src/Lucene.Net/Util/PrintStreamInfoStream.cs @@ -1,4 +1,4 @@ -using J2N.Threading.Atomic; +using J2N.Threading.Atomic; using Lucene.Net.Support.IO; using System; using System.IO; @@ -90,6 +90,7 @@ protected override void Dispose(bool disposing) { m_stream.Dispose(); } + base.Dispose(disposing); // LUCENENET specific - disposable pattern requires calling the base class implementation } public virtual bool IsSystemStream => isSystemStream; diff --git a/src/dotnet/tools/lucene-cli/CommandLine/CommandLineApplication.cs b/src/dotnet/tools/lucene-cli/CommandLine/CommandLineApplication.cs index f5971e5cc3..e3d8240f03 100644 --- a/src/dotnet/tools/lucene-cli/CommandLine/CommandLineApplication.cs +++ b/src/dotnet/tools/lucene-cli/CommandLine/CommandLineApplication.cs @@ -534,7 +534,7 @@ private static void HandleUnexpectedArg(CommandLineApplication command, string[] } } - private class CommandArgumentEnumerator : IEnumerator + private sealed class CommandArgumentEnumerator : IEnumerator { private readonly IEnumerator _enumerator; diff --git a/src/dotnet/tools/lucene-cli/SourceCode/SourceCodeSectionReader.cs b/src/dotnet/tools/lucene-cli/SourceCode/SourceCodeSectionReader.cs index 0ec50949ea..c33eebafb2 100644 --- a/src/dotnet/tools/lucene-cli/SourceCode/SourceCodeSectionReader.cs +++ b/src/dotnet/tools/lucene-cli/SourceCode/SourceCodeSectionReader.cs @@ -150,6 +150,7 @@ protected override void Dispose(bool disposing) { this.reader?.Dispose(); } + base.Dispose(disposing); } } }