Skip to content

Commit 3461f74

Browse files
committed
Apply same fix as last commit to ReverseComparer<T> too
1 parent 7f21c8c commit 3461f74

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/Lucene.Net/Support/Collections.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,17 @@ public static ReadOnlyDictionary<TKey, TValue> AsReadOnly<TKey, TValue>(IDiction
194194

195195
#region ReverseComparer
196196

197-
private class ReverseComparer<T> : IComparer<T?>
197+
private class ReverseComparer<T> : IComparer<T>
198198
{
199199
internal static readonly ReverseComparer<T> REVERSE_ORDER = new ReverseComparer<T>();
200200

201201
public int Compare(T? x, T? y)
202202
{
203+
// [!]: In .NET Framework and Standard, it thinks that IComparer<T>.Compare cannot take nulls.
204+
// In .NET 8, it is typed to allow nulls. We will assume that the passed comparer can handle nulls
205+
// if used with a nullable type.
203206
// LUCENENET specific: Use J2N's Comparer<T> to mimic Java comparison behavior
204-
return JCG.Comparer<T?>.Default.Compare(y, x);
207+
return JCG.Comparer<T>.Default.Compare(y!, x!);
205208
}
206209
}
207210

0 commit comments

Comments
 (0)