lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [lucenenet] 10/29: BUG: Fixes TestMultiTermConstantScore cleanup - safely call Dispose by ensuring the reference variable is not null
Date Tue, 09 Jul 2019 21:29:26 GMT
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

commit 6eebe37009b360447102aad70809670f91ab81af
Author: Shad Storhaug <shad@shadstorhaug.com>
AuthorDate: Tue Jul 9 05:41:04 2019 +0700

    BUG: Fixes TestMultiTermConstantScore cleanup - safely call Dispose by ensuring the reference
variable is not null
---
 src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs |  8 +++---
 .../Search/TestMultiTermConstantScore.cs           | 29 +++++++++++-----------
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs b/src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs
index 61e0c17..412ce9f 100644
--- a/src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs
+++ b/src/Lucene.Net.Tests/Search/BaseTestRangeFilter.cs
@@ -116,10 +116,10 @@ namespace Lucene.Net.Search
         [OneTimeTearDown]
         public override void AfterClass() // LUCENENET specific: renamed from AfterClassBaseTestRangeFilter()
so we can override to control the order of execution
         {
-            SignedIndexReader.Dispose();
-            UnsignedIndexReader.Dispose();
-            SignedIndexDir.Index.Dispose();
-            UnsignedIndexDir.Index.Dispose();
+            SignedIndexReader?.Dispose();
+            UnsignedIndexReader?.Dispose();
+            SignedIndexDir.Index?.Dispose();
+            UnsignedIndexDir.Index?.Dispose();
             SignedIndexReader = null;
             UnsignedIndexReader = null;
             SignedIndexDir = null;
diff --git a/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs b/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
index e98380b..d3cd760 100644
--- a/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
+++ b/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
@@ -67,24 +67,25 @@ namespace Lucene.Net.Search
             string[] data = new string[] { "A 1 2 3 4 5 6", "Z       4 5 6", null, "B   2
  4 5 6", "Y     3   5 6", null, "C     3     6", "X       4 5 6" };
 
             Small = NewDirectory();
-            RandomIndexWriter writer = new RandomIndexWriter(Random(), Small, NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)).SetMergePolicy(NewLogMergePolicy()));
-
-            FieldType customType = new FieldType(TextField.TYPE_STORED);
-            customType.IsTokenized = false;
-            for (int i = 0; i < data.Length; i++)
+            using (RandomIndexWriter writer = new RandomIndexWriter(Random(), Small, NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)).SetMergePolicy(NewLogMergePolicy())))
             {
-                Document doc = new Document();
-                doc.Add(NewField("id", Convert.ToString(i), customType)); // Field.Keyword("id",String.valueOf(i)));
-                doc.Add(NewField("all", "all", customType)); // Field.Keyword("all","all"));
-                if (null != data[i])
+
+                FieldType customType = new FieldType(TextField.TYPE_STORED);
+                customType.IsTokenized = false;
+                for (int i = 0; i < data.Length; i++)
                 {
-                    doc.Add(NewTextField("data", data[i], Field.Store.YES)); // Field.Text("data",data[i]));
+                    Document doc = new Document();
+                    doc.Add(NewField("id", Convert.ToString(i), customType)); // Field.Keyword("id",String.valueOf(i)));
+                    doc.Add(NewField("all", "all", customType)); // Field.Keyword("all","all"));
+                    if (null != data[i])
+                    {
+                        doc.Add(NewTextField("data", data[i], Field.Store.YES)); // Field.Text("data",data[i]));
+                    }
+                    writer.AddDocument(doc);
                 }
-                writer.AddDocument(doc);
-            }
 
-            Reader = writer.Reader;
-            writer.Dispose();
+                Reader = writer.Reader;
+            }
         }
 
         [OneTimeTearDown]


Mime
View raw message