Skip to content

Precision gap: self-detaching event handler (unsubscribes itself in its own body) flagged as unbounded #224

Description

@PhysShell

Found by: the issue #201 oracle sweep, docs/notes/oracle-sweep-2026-07-10.md; catalogued as docs/notes/field-notes-patterns.md entry 18.

The pattern

DropDownContent.Closed += DropDownContent_Closed;   // <- flagged: no visible -= near the +=

void DropDownContent_Closed(object sender, EventArgs e) {
    ((Popup)sender).Closed -= DropDownContent_Closed;   // removes itself, first firing
    this.IsDropDownContentOpen = false;
}

The handler removes itself from the event the first time it runs — a common one-shot idiom ("do this once, then stop listening") that needs no external detach call. By the time the event could fire a second time, the subscription is already gone.

Own.NET's -= search is scoped to the subscribe call's enclosing method (or a class-level scan for a field-based handler); it doesn't look inside the handler's own body for a matching self-removal.

Evidence

  • AvalonEdit ICSharpCode.AvalonEdit/Search/DropDownButton.cs:78-86

Suggested direction (not prescriptive)

When resolving whether a subscribed handler has a matching -=, also check the handler method's own body for a -= against the same event/delegate expression (typically via the sender parameter cast back to the source type) — a handler that detaches itself is bounded by construction.

Scope

No analyzer code changed as part of the sweep — this issue tracks the fix as its own unit of work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions