diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs index ceeb7eb532..4a06fcb3ee 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs @@ -910,7 +910,8 @@ private void ReadDictionaryFiles(IList dictionaries, Encoding decoder, B { foreach (Stream dictionary in dictionaries) { - using var lines = new StreamReader(dictionary, decoder); // LUCENENET specific - CA2000: Use using pattern to ensure reader is disposed + // LUCENENET specific - CA2000: Use using pattern to ensure reader is disposed, although we want to leave the dictionary stream open. See: TestDictionary.TestResourceCleanup + using var lines = new StreamReader(dictionary, decoder, detectEncodingFromByteOrderMarks: true, bufferSize: -1, leaveOpen: true); string line = lines.ReadLine(); // first line is number of entries (approximately, sometimes) while ((line = lines.ReadLine()) != null) diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs index 7ff4779762..0a9d12e9b9 100644 --- a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs +++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs @@ -376,7 +376,7 @@ IEnumerator IEnumerable.GetEnumerator() } // per-document vint-encoded byte[] - internal class SortedSetEnumerator : IEnumerator + internal sealed class SortedSetEnumerator : IEnumerator { internal byte[] buffer = new byte[10]; internal ByteArrayDataOutput @out = new ByteArrayDataOutput(); @@ -426,7 +426,7 @@ public bool MoveNext() object IEnumerator.Current => Current; // encodes count values to buffer - internal virtual void EncodeValues(int count) + internal void EncodeValues(int count) { @out.Reset(buffer); long lastOrd = 0; @@ -450,4 +450,4 @@ public void Dispose() } } #pragma warning restore 612, 618 -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Hunspell/TestDictionary.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Hunspell/TestDictionary.cs index 206c023ff8..934a99595c 100644 --- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Hunspell/TestDictionary.cs +++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Hunspell/TestDictionary.cs @@ -156,7 +156,7 @@ public override long Position set => @delegate.Position = value; } - public CloseCheckInputStream(TestDictionary outerInstance, System.IO.Stream @delegate) + public CloseCheckInputStream(TestDictionary outerInstance, System.IO.Stream @delegate) { this.@delegate = @delegate; this.outerInstance = outerInstance; @@ -164,17 +164,10 @@ public CloseCheckInputStream(TestDictionary outerInstance, System.IO.Stream @del protected override void Dispose(bool disposing) { + disposed = true; @delegate.Dispose(); } - - new public void Dispose() - { - this.disposed = true; - base.Dispose(); - } - - public virtual bool Disposed => this.disposed; public override void Flush() @@ -209,7 +202,7 @@ public virtual void TestResourceCleanup() CloseCheckInputStream affixStream = new CloseCheckInputStream(this, this.GetType().getResourceAsStream("compressed.aff")); CloseCheckInputStream dictStream = new CloseCheckInputStream(this, this.GetType().getResourceAsStream("compressed.dic")); - new Dictionary(affixStream, dictStream); + _ = new Dictionary(affixStream, dictStream); assertFalse(affixStream.Disposed); assertFalse(dictStream.Disposed); @@ -289,4 +282,4 @@ public virtual void TestFlagWithCrazyWhitespace() assertNotNull(Dictionary.GetFlagParsingStrategy("FLAG UTF-8")); } } -} \ No newline at end of file +}