Skip to content

Commit 6ac506f

Browse files
paulirwinclaude
andcommitted
Enable nullable on DrainReclaimer
Add #nullable enable to match the adjacent Support/ files and annotate the two null-bearing fields (_unmap, OnEnterForTest). The _unmap invocation in TryReclaim uses the null-forgiving operator with a comment: it is non-null there by the Close-publishes-before-_closed invariant the analyzer can't see across methods. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0acaaa6 commit 6ac506f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/Lucene.Net/Support/DrainReclaimer.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Runtime.CompilerServices;
55
using System.Threading;
66

7+
#nullable enable
8+
79
namespace Lucene.Net.Support
810
{
911
/*
@@ -66,7 +68,7 @@ internal sealed class Slot
6668
// Test-only hook: when set, Enter parks here (inside the bracket) so a
6769
// test can drive a concurrent Close while this reader is mid-dereference.
6870
// Null on every production read; a single predictably-not-taken branch.
69-
internal Action OnEnterForTest;
71+
internal Action? OnEnterForTest;
7072

7173
internal Slot(DrainReclaimer owner) => this.owner = owner;
7274

@@ -188,7 +190,7 @@ internal readonly ref struct ReadScope
188190
private readonly List<Slot> _slots = new();
189191

190192
private volatile bool _closed;
191-
private Action _unmap;
193+
private Action? _unmap;
192194
private int _reclaimed;
193195

194196
// Upper bound on how long Close actively spins waiting for readers to drain
@@ -261,10 +263,12 @@ private bool TryReclaim()
261263
return false;
262264
}
263265

264-
// First caller to win the swap runs the unmap exactly once.
266+
// First caller to win the swap runs the unmap exactly once. _unmap is
267+
// non-null here: Close assigns it before publishing _closed, and we only
268+
// reach this branch with _closed == true and _reclaimed won from 0.
265269
if (Interlocked.Exchange(ref _reclaimed, 1) == 0)
266270
{
267-
_unmap();
271+
_unmap!();
268272
_unmap = null;
269273
}
270274
return true;

0 commit comments

Comments
 (0)