You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2020/11/05 03:58:50 UTC
[lucenenet] branch master updated: Lucene.Net.Util.Automaton.State:
Removed IEquatable and other equality checking,
as implementing Equals() to compare other than reference equality causes
IndexOutOfRangeException to randomly occur when using FuzzyTermsEnum. Fixes
#296.
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 6ea55d1 Lucene.Net.Util.Automaton.State: Removed IEquatable<T> and other equality checking, as implementing Equals() to compare other than reference equality causes IndexOutOfRangeException to randomly occur when using FuzzyTermsEnum. Fixes #296.
6ea55d1 is described below
commit 6ea55d1bcacd9322f10b696e3eee4462905a1479
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Thu Nov 5 10:03:44 2020 +0700
Lucene.Net.Util.Automaton.State: Removed IEquatable<T> and other equality checking, as implementing Equals() to compare other than reference equality causes IndexOutOfRangeException to randomly occur when using FuzzyTermsEnum. Fixes #296.
---
src/Lucene.Net/Util/Automaton/State.cs | 58 ++++------------------------------
1 file changed, 7 insertions(+), 51 deletions(-)
diff --git a/src/Lucene.Net/Util/Automaton/State.cs b/src/Lucene.Net/Util/Automaton/State.cs
index 916703c..f175d36 100644
--- a/src/Lucene.Net/Util/Automaton/State.cs
+++ b/src/Lucene.Net/Util/Automaton/State.cs
@@ -41,7 +41,7 @@ namespace Lucene.Net.Util.Automaton
/// <para/>
/// @lucene.experimental
/// </summary>
- public class State : IComparable<State>, IEquatable<State> // LUCENENET specific: Implemented IEquatable, since this class is used in hashtables
+ public class State : IComparable<State>
{
internal bool accept;
[WritableArray]
@@ -355,60 +355,16 @@ namespace Lucene.Net.Util.Automaton
return s.id - id;
}
- #region Equality
- // LUCENENET specific - implemented IEquatable.
- public bool Equals(State other)
- {
- if (other == null)
- return false;
- return id.Equals(other.id);
- }
+ // LUCENENET NOTE: DO NOT IMPLEMENT Equals()!!!
+ // Although it doesn't match GetHashCode(), checking for
+ // reference equality is by design.
+ // Implementing Equals() causes difficult to diagnose
+ // IndexOutOfRangeExceptions when using FuzzyTermsEnum.
+ // See GH-296.
public override int GetHashCode()
{
return id;
}
-
- public override bool Equals(object obj)
- {
- return ReferenceEquals(this, obj) || obj is State other && Equals(other);
- }
-
- public static bool operator ==(State left, State right)
- {
- if (left is null)
- {
- return right is null;
- }
-
- return left.Equals(right);
- }
-
- public static bool operator !=(State left, State right)
- {
- return !(left == right);
- }
-
- public static bool operator <(State left, State right)
- {
- return left is null ? !(right is null) : left.CompareTo(right) < 0;
- }
-
- public static bool operator <=(State left, State right)
- {
- return left is null || left.CompareTo(right) <= 0;
- }
-
- public static bool operator >(State left, State right)
- {
- return !(left is null) && left.CompareTo(right) > 0;
- }
-
- public static bool operator >=(State left, State right)
- {
- return left is null ? right is null : left.CompareTo(right) >= 0;
- }
-
- #endregion
}
}
\ No newline at end of file