{"record":{"id":"abcbc52d94c4a493","repo":"dotnet/reactive","slug":"source-isempty","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/IsEmpty.cs","lineNumber":12,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<bool> IsEmpty<TSource>(this IAsyncObservable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return Create<TSource, bool>(source, static (source, observer) => source.SubscribeSafeAsync(AsyncObserver.IsEmpty<TSource>(observer)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> IsEmpty<TSource>(IAsyncObserver<bool> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Any<TSource>(Select<bool, bool>(observer, b => !b));\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/IsEmpty.cs#L1-L29","documentation":"IsEmpty validates the source observable at operator-creation time; without a source there is nothing whose emptiness can be checked. Standard ArgumentNullException guard in the LINQ operator. Fix: pass a non-null IAsyncObservable<TSource>.","triggerScenarios":"Calling source.IsEmpty() on a null receiver or AsyncObservable.IsEmpty(null), typically from a nullable observable obtained via lookup, config, or a null-returning method.","commonSituations":"Fluent chains built on results of methods that can return null (repository/cache lookups), especially when combining multiple query results.","solutions":["Ensure the source IAsyncObservable<TSource> is non-null before calling IsEmpty; fall back to AsyncObservable.Empty<TSource>().","Trace the producer of the null observable and make it return an empty observable instead of null.","Add a null guard before the operator chain."],"exampleFix":"// before\nvar empty = GetSource()?.IsEmpty(); // NullReference or ANE path\n// after\nvar src = GetSource() ?? AsyncObservable.Empty<int>();\nvar empty = src.IsEmpty();","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentException(\"source must be non-null\");\n// or: source ??= AsyncObservable.Empty<TSource>();","typeGuard":"static bool HasSource<TSource>(IAsyncObservable<TSource> s) => s is not null;","tryCatchPattern":"try { var isEmpty = src.IsEmpty(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* substitute Empty<TSource>() */ }","preventionTips":["Make stream-producing APIs return empty streams instead of null","Apply ?? Empty<T>() before operator chains","Use nullable reference type annotations on stream-producing methods"],"tags":["argument-null","operators","reactive"],"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"}