Repository navigation
fix: a range set refuses a null range instead of storing it - #370
Merged
Merged
Conversation
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
enabled auto-merge
October 24, 2026 16:13
This was referenced Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #356
Problem
A
nullrange went into a range set.RangeSet<DateRange, DateOnly>.From([null!])built a set whose one element wasnull.Countwas 1,IsEmpty()andEquals(Empty)returnedfalse, and the firstContainsthrewNullReferenceException. That breaks the set's rule (sorted, disjoint, non-adjacent, no empties) on a construction path.Other inputs failed differently:
FromthrewInvalidOperationExceptionwhile sorting.(,)the null was ignored, because the loop returned at the first infinity.ExceptandUnioncalled on a null range reached the same paths.Change
RangeSet.cs: bothNormalizeloops and the single-element fast path throwArgumentException("A range set cannot contain a null range.", "ranges")for a null anywhere in the input. The loops now read every input after an infinity too, so[(,), null]is refused rather than collapsed.FromandRangeSet.Createdocument the exception.ArgumentExceptionand not theArgumentNullExceptionRangeSet.From accepts a null element: the set holds null, IsEmpty() is false and Contains throws #356 named: this is the value sets' rule.ValueSetCorethrowsArgumentException("Value sets cannot contain null elements.", nameof(values))for a null element, and keepsArgumentNullExceptionfor a bare null argument (Add,Remove,Contains). The collection isn't null; one of its elements is. RangeSet.From accepts a null element: the set holds null, IsEmpty() is false and Contains throws #356 and 10.x: a predicate over a null range, RangeSet or value set is false in memory and in SQL (port of the predicate half of #350, #355 and #356) #357 are updated to say so.RangeSetNullContractTests(conventions), registered inoracles.jsonas anexceptionoracle besideValueSetNullContractTests, with the seedrangeset-stores-a-null-range.patch.docs/ranges.md: under the three construction rules, "Anullrange is not an empty range, so it isn't dropped. Creating a set from one throwsArgumentException, wherever it stands among the inputs." Claim M18 quotes it.docs/migration.md: a bullet and### Keep null out of a range setunder## Migration from v10.x.Ranges:line under### Breakingin[11.0.0-preview.1], since a silent fix into a major's preview goes there. The 10.x side ships inside 10.x: a predicate over a null range, RangeSet or value set is false in memory and in SQL (port of the predicate half of #350, #355 and #356) #357.test/oracles/candidates.json: 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'sUnion(Infinite).Contains(v) on DateRange? null:reportedcandidate fixedand is removed.null.Union((,))returned{(,)}and now throws, so memory has no answer for that row, as 10.x: a predicate over a null range, RangeSet or value set is false in memory and in SQL (port of the predicate half of #350, #355 and #356) #357 anticipated. 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 keeps 11 candidates.Tests
Local, SDK
11.0.100-rc.2.26504.105, Docker (OrbStack).RangeSetNullContractTests.EveryRangeType_RefusesANullRangeInEveryConstructionPathdiscovers every range type of both libraries (at least 13). For each it checks[null],[null, finite],[finite, null],[empty, null]and[(,), null]throughFrom(IEnumerable),From(span)andRangeSet.Create, each withThrowsExactly<ArgumentException>.UnionandExcepton a null range are checked withThrows<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 laterArgumentNullException, a subclass, keeps it green.dotnet run tools/oracles.cs seeds rangeset-storesreports it caught, 1 of 1 tests failing.RangeSet.csseeds still apply (git apply --check); the change doesn't touch their context.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 withcandidate fixedfor the entry removed above.🤖 Generated with Claude Code