Skip to content

Commit

Permalink
BUG: Lucene.Net.Search.FieldComparer.TermValComparer: Using a singlet…
Browse files Browse the repository at this point in the history
…on instance breaks missing vs empty field comparison because the static fields MISSING_BYTES and NON_MISSING_BYTES are tested for reference equality.
  • Loading branch information
NightOwl888 committed Feb 9, 2024
1 parent 18d10cf commit 8e60f39
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Lucene.Net/Search/FieldComparator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,10 +1452,14 @@ public override int CompareValues(BytesRef val1, BytesRef val2)
// TODO: should we remove this? who really uses it?
public sealed class TermValComparer : FieldComparer<BytesRef>
{
// LUCENENET NOTE: We can't use Arrays.Empty<byte>() here because
// MISSING_BYTES and NON_MISSING_BYTES are compared for reference
// equality and Arrays.Empty<byte>() returns a singleton instance.

// sentinels, just used internally in this comparer
private static readonly byte[] MISSING_BYTES = Arrays.Empty<byte>();
private static readonly byte[] MISSING_BYTES = new byte[0];

private static readonly byte[] NON_MISSING_BYTES = Arrays.Empty<byte>();
private static readonly byte[] NON_MISSING_BYTES = new byte[0];

private readonly BytesRef[] values; // LUCENENET: marked readonly
private BinaryDocValues docTerms;
Expand Down Expand Up @@ -1577,4 +1581,4 @@ private void SetMissingBytes(int doc, BytesRef br)
}
}
}
}
}

0 comments on commit 8e60f39

Please sign in to comment.