This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/master by this push:
new ad5d70a3b IDisposable Pattern Cleanup and fix
TestDictionary.TestResourceCleanup, #265 (#1095)
ad5d70a3b is described below
commit ad5d70a3b0d3f41c7ed43d5cf86d385908513277
Author: Paul Irwin <[email protected]>
AuthorDate: Sat Jan 11 22:21:46 2025 -0700
IDisposable Pattern Cleanup and fix TestDictionary.TestResourceCleanup,
#265 (#1095)
* IDisposable Pattern Cleanup, #265
* Fix default StreamReader buffer size for .NET Framework compat
---
.../Analysis/Hunspell/Dictionary.cs | 3 ++-
.../Codecs/Lucene42/Lucene42DocValuesConsumer.cs | 6 +++---
.../Analysis/Hunspell/TestDictionary.cs | 15 ++++-----------
3 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs
b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs
index b790df5e6..3055bbe2b 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 @@ namespace Lucene.Net.Analysis.Hunspell
{
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: 1024, 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 7ff477976..0a9d12e9b 100644
--- a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
@@ -376,7 +376,7 @@ namespace Lucene.Net.Codecs.Lucene42
}
// per-document vint-encoded byte[]
- internal class SortedSetEnumerator : IEnumerator<BytesRef>
+ internal sealed class SortedSetEnumerator : IEnumerator<BytesRef>
{
internal byte[] buffer = new byte[10];
internal ByteArrayDataOutput @out = new ByteArrayDataOutput();
@@ -426,7 +426,7 @@ namespace Lucene.Net.Codecs.Lucene42
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 @@ namespace Lucene.Net.Codecs.Lucene42
}
}
#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 206c023ff..934a99595 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 @@ namespace Lucene.Net.Analysis.Hunspell
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 @@ namespace Lucene.Net.Analysis.Hunspell
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 @@ namespace Lucene.Net.Analysis.Hunspell
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 @@ namespace Lucene.Net.Analysis.Hunspell
assertNotNull(Dictionary.GetFlagParsingStrategy("FLAG UTF-8"));
}
}
-}
\ No newline at end of file
+}