Copilot commented on code in PR #1124:
URL: https://github.com/apache/lucenenet/pull/1124#discussion_r2354176119
##########
src/Lucene.Net/Support/Collections.cs:
##########
@@ -227,22 +195,22 @@ public static ReadOnlyDictionary<TKey, TValue>
AsReadOnly<TKey, TValue>(IDiction
#region ReverseComparer
- private class ReverseComparer<T> : IComparer<T>
+ private class ReverseComparer<T> : IComparer<T?>
{
internal static readonly ReverseComparer<T> REVERSE_ORDER = new
ReverseComparer<T>();
- public int Compare(T x, T y)
+ public int Compare(T? x, T? y)
{
// LUCENENET specific: Use J2N's Comparer<T> to mimic Java
comparison behavior
- return JCG.Comparer<T>.Default.Compare(y, x);
+ return JCG.Comparer<T?>.Default.Compare(y, x);
Review Comment:
The generic type parameter should be `T` instead of `T?`. The `Compare`
method parameters are nullable but the comparer itself should operate on the
original type `T` to maintain consistency with the class definition and avoid
potential issues with value types.
##########
src/Lucene.Net/Support/Collections.cs:
##########
@@ -252,20 +220,21 @@ private class ReverseComparer2<T> : IComparer<T>
*
* @serial
*/
- internal readonly IComparer<T> cmp;
+ internal readonly IComparer<T?> cmp;
public ReverseComparer2(IComparer<T> cmp)
{
+ // ReSharper disable once
ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (Debugging.AssertsEnabled) Debugging.Assert(cmp != null);
- this.cmp = cmp;
+ this.cmp = cmp!;
Review Comment:
The ReSharper disable comment and null-forgiving operator are inconsistent
with the parameter being nullable. Either make the parameter non-nullable if
null is not expected, or handle the null case properly without using the
null-forgiving operator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]