{"record":{"id":"7a203cb6112edc2e","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-clock","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(clock));","messagePattern":"throw new ArgumentNullException\\(nameof\\(clock\\)\\);","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/TimeInterval.cs","lineNumber":24,"sourceCode":"\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TimeInterval<TSource>> TimeInterval<TSource>(this IAsyncObservable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return Create<TSource, TimeInterval<TSource>>(source, static (source, observer) => source.SubscribeSafeAsync(AsyncObserver.TimeInterval(observer)));\n        }\n\n        public static IAsyncObservable<TimeInterval<TSource>> TimeInterval<TSource>(this IAsyncObservable<TSource> source, IClock clock)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (clock == null)\n                throw new ArgumentNullException(nameof(clock));\n\n            return CreateAsyncObservable<TimeInterval<TSource>>.From(\n                source,\n                clock,\n                static (source, clock, observer) => source.SubscribeSafeAsync(AsyncObserver.TimeInterval(observer, clock))); ;\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> TimeInterval<TSource>(IAsyncObserver<TimeInterval<TSource>> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return TimeInterval(observer, Clock.Default);\n        }\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/TimeInterval.cs#L6-L42","documentation":"The clock-taking TimeInterval overload requires a non-null IClock because it reads clock.Now to compute inter-notification intervals. A null clock makes interval computation impossible, so the operator throws ArgumentNullException before building the composed observable.","triggerScenarios":"Calling source.TimeInterval(clock) with clock == null, e.g. an IClock resolved from config/DI that was never registered or a variable that shadows a null.","commonSituations":"Missing clock registration in a DI container; test setups where a mock clock was not assigned; forgetting that the parameterless overload defaults to Clock.Default.","solutions":["Pass Clock.Default or a TestClock/MockClock instance explicitly","Use the parameterless source.TimeInterval() overload which defaults to Clock.Default","Fix the null-producing clock factory/lookup"],"exampleFix":"// before\nvar intervals = source.TimeInterval(clock); // clock null\n// after\nvar intervals = source.TimeInterval(clock ?? Clock.Default);","handlingStrategy":"validation","validationCode":"clock ??= Clock.Default;\nvar intervals = source.TimeInterval(clock);","typeGuard":"bool IsValidClock(IClock? c) => c is not null;","tryCatchPattern":"try\n{\n    intervals = source.TimeInterval(clock);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"clock\")\n{\n    intervals = source.TimeInterval(); // defaults to Clock.Default\n}","preventionTips":["Use the parameterless TimeInterval overload unless a custom clock is needed","Register IClock in DI with a non-null default","Assert clock non-null in test setup"],"tags":["argument-null","clock","validation"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}