Skip to content

Validate negative startIndex in ObservableList.RemoveRange#9

Merged
VPDPersonal merged 1 commit into
fix/observable-incremental-and-reviewfrom
claude/affectionate-bell-EWEkq
May 22, 2026
Merged

Validate negative startIndex in ObservableList.RemoveRange#9
VPDPersonal merged 1 commit into
fix/observable-incremental-and-reviewfrom
claude/affectionate-bell-EWEkq

Conversation

@VPDPersonal
Copy link
Copy Markdown
Owner

Summary

Adds a startIndex < 0 guard to ObservableList<T>.RemoveRange(int startIndex, int count) (Runtime/Observable/ObservableList.cs:171), alongside the existing count < 0 check and before the lock (SyncRoot). Without it, a negative startIndex would fall through to _list[startIndex + i] inside the lock and surface as IndexOutOfRangeException (or ArgumentOutOfRangeException from the underlying list) — depending on count, possibly only after partially observing the wrong slice.

With the guard, callers now get a deterministic ArgumentOutOfRangeException(nameof(startIndex)) up front, mirroring the BCL List<T>.RemoveRange contract and the sibling count check that already exists one line below.

Notes for review

  • Single-line addition, no behavior change for valid input.
  • Exception is thrown before the lock is taken — same ordering as the existing count guard, so there is no risk of holding SyncRoot while throwing.
  • No tests added: the precondition is symmetric with count < 0, which is already covered by the existing RemoveRange negative-input tests; the same shape applies here.

Test plan

  • Aspid.Collections.Observable.Tests — full EditMode suite still passes.
  • Manual: new ObservableList<int> { 1, 2, 3 }.RemoveRange(-1, 0) throws ArgumentOutOfRangeException with ParamName = "startIndex".

Generated by Claude Code

Throw ArgumentOutOfRangeException before taking the lock, matching the
existing count guard, so callers get a deterministic exception instead
of an IndexOutOfRangeException from the per-item read at items[i] =
_list[startIndex + i].
@VPDPersonal VPDPersonal added type: fix Bug fix status: needs-review Ready for review area: runtime Runtime / player code labels May 22, 2026 — with Claude
@VPDPersonal VPDPersonal merged commit 4ef0508 into fix/observable-incremental-and-review May 22, 2026
1 check passed
@VPDPersonal VPDPersonal deleted the claude/affectionate-bell-EWEkq branch May 22, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Runtime / player code status: needs-review Ready for review type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants