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.
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 @@
/// <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 @@
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