Skip to content

fix: a range set refuses a null range instead of storing it - #370

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/356-rangeset-from-null
Oct 24, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/356-rangeset-from-null

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #356

Problem

A null range went into a range set. RangeSet<DateRange, DateOnly>.From([null!]) built a set whose one element was null. Count was 1, IsEmpty() and Equals(Empty) returned false, and the first Contains threw NullReferenceException. That breaks the set's rule (sorted, disjoint, non-adjacent, no empties) on a construction path.

Other inputs failed differently:

  • With two or more inputs, From threw InvalidOperationException while sorting.
  • Next to (,) the null was ignored, because the loop returned at the first infinity.
  • Except and Union called on a null range reached the same paths.

Change

Tests

Local, SDK 11.0.100-rc.2.26504.105, Docker (OrbStack).

  • RangeSetNullContractTests.EveryRangeType_RefusesANullRangeInEveryConstructionPath discovers every range type of both libraries (at least 13). For each it checks [null], [null, finite], [finite, null], [empty, null] and [(,), null] through From(IEnumerable), From(span) and RangeSet.Create, each with ThrowsExactly<ArgumentException>. Union and Except on a null range are checked with Throws<ArgumentException>, so A null range answers some extensions in memory and throws on others, and the answers it gives disagree with PostgreSQL on a NULL column #350's later ArgumentNullException, a subclass, keeps it green.
  • The seed (the three null checks removed): dotnet run tools/oracles.cs seeds rangeset-stores reports it caught, 1 of 1 tests failing.
  • The five existing RangeSet.cs seeds still apply (git apply --check); the change doesn't touch their context.
  • Full suite on postgres:16-alpine: all eight projects pass (core 1399, NodaTime 239, EF 293, EF NodaTime 83, ASP.NET Core 92, conventions 408, integration 287, infinity-disabled 4). The first run failed only with candidate fixed for the entry removed above.

🤖 Generated with Claude Code

RangeSet.From, the collection-expression builder RangeSet.Create, and through
them Union and Except called on a null range, built a set whose one element was
null: Count 1, IsEmpty() false, Equals(Empty) false, and the first Contains threw
NullReferenceException. With two or more inputs From threw while sorting, and
next to (,) the null was ignored, because the loop returned at the first infinity.

Both normalize loops and the single-element fast path now throw
ArgumentException ("A range set cannot contain a null range.", ranges) for a null
anywhere in the input, reading every input after an infinity too. That is the
value sets' rule: a null element refused with ArgumentException, never dropped,
because a null range is not an empty one.

RangeSetNullContractTests (conventions, registered as an exception oracle beside
ValueSetNullContractTests) discovers every range type of both libraries and puts
the null first, after a bounded, the empty and the infinite range, through both
From overloads and Create, plus Union and Except on a null range. Its seed
rangeset-stores-a-null-range.patch is caught. Claim M18 quotes the new
docs/ranges.md sentence. #350's Union(Infinite).Contains(v) candidate reports
fixed, since memory now throws for it, and is removed.

Found-By: CA
Defect-Class: CAN

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Oct 24, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred breaking Changes an answer or a signature — needs a major area/range-set RangeSet and multirange algebra package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference labels Oct 24, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit ded685a into main Oct 24, 2026
11 of 14 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/356-rangeset-from-null branch October 24, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/range-set RangeSet and multirange algebra breaking Changes an answer or a signature — needs a major bug Something isn't working package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RangeSet.From accepts a null element: the set holds null, IsEmpty() is false and Contains throws

1 participant