lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [lucenenet] 35/35: BUG: Lucene.Net.Search.BooleanClause::Equals(BooleanClause): Fixed potential null reference exception when Query is set to null
Date Sun, 09 Feb 2020 06:16:27 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 f9e8fc0c8f71448927f91b015d3582d7b6675fd1
Author: Shad Storhaug <shad@shadstorhaug.com>
AuthorDate: Sat Feb 8 19:42:53 2020 +0700

    BUG: Lucene.Net.Search.BooleanClause::Equals(BooleanClause): Fixed potential null reference
exception when Query is set to null
---
 src/Lucene.Net/Search/BooleanClause.cs | 61 +++++++++++-----------------------
 1 file changed, 19 insertions(+), 42 deletions(-)

diff --git a/src/Lucene.Net/Search/BooleanClause.cs b/src/Lucene.Net/Search/BooleanClause.cs
index cd81e97..fff6043 100644
--- a/src/Lucene.Net/Search/BooleanClause.cs
+++ b/src/Lucene.Net/Search/BooleanClause.cs
@@ -65,50 +65,27 @@ namespace Lucene.Net.Search
 
         public virtual Occur Occur
         {
-            get
-            {
-                return occur;
-            }
-            set
-            {
-                occur = value;
-            }
+            get => occur;
+            set => occur = value;
         }
 
         public virtual Query Query
         {
-            get
-            {
-                return query;
-            }
-            set
-            {
-                query = value;
-            }
+            get => query;
+            set => query = value;
         }
 
-        public virtual bool IsProhibited
-        {
-            get
-            {
-                return Occur.MUST_NOT == occur;
-            }
-        }
+        public virtual bool IsProhibited => Occur.MUST_NOT == occur;
 
-        public virtual bool IsRequired
-        {
-            get
-            {
-                return Occur.MUST == occur;
-            }
-        }
+        public virtual bool IsRequired => Occur.MUST == occur;
 
         /// <summary>
         /// Returns <c>true</c> if <paramref name="o"/> is equal to this.
</summary>
         public override bool Equals(object o)
         {
-            BooleanClause bc = o as BooleanClause;
-            return this.Equals(bc);
+            if (o is BooleanClause other)
+                return this.Equals(other);
+            return false;
         }
 
         /// <summary>
@@ -123,16 +100,16 @@ namespace Lucene.Net.Search
         // LUCENENET specific
         public bool Equals(BooleanClause other)
         {
-            bool success = true;
-            if (object.ReferenceEquals(null, other))
-            {
-                return object.ReferenceEquals(null, this); // LUCENENET TODO: This can never
happen - revert to original code
-            }
-            if (query == null)
-            {
-                success &= other.Query == null;
-            }
-            return success && this.query.Equals(other.query) && this.occur
== other.occur;
+            if (null == other)
+                return false;
+
+            bool success;
+            if (query is null)
+                success = other.Query is null;
+            else
+                success = query.Equals(other.query);
+
+            return success && this.occur == other.occur;
         }
 
         public override string ToString()


Mime
View raw message