{"record":{"id":"a8775d16e90a3db9","repo":"App-vNext/Polly","slug":"value-cannot-be-null-a8775d","errorCode":null,"errorMessage":"Value cannot be null.","messagePattern":"Value cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Bulkhead/BulkheadPolicy.cs","lineNumber":34,"sourceCode":"        int maxParallelization,\n        int maxQueueingActions,\n        Action<Context> onBulkheadRejected)\n    {\n        MaxQueueingActions = maxQueueingActions;\n        _onBulkheadRejected = onBulkheadRejected;\n\n        (_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions);\n    }\n\n    private int MaxQueueingActions { get; }\n\n    /// <inheritdoc/>\n    [DebuggerStepThrough]\n    protected override TResult Implementation<TResult>(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)\n    {\n        if (action is null)\n        {\n            throw new ArgumentNullException(nameof(action));\n        }\n\n        return BulkheadEngine.Implementation(\n            action,\n            context,\n            _onBulkheadRejected,\n            _maxParallelizationSemaphore,\n            _maxQueuedActionsSemaphore,\n            cancellationToken);\n    }\n\n    /// <summary>\n    /// Gets the number of slots currently available for executing actions through the bulkhead.\n    /// </summary>\n    public int BulkheadAvailableCount => _maxParallelizationSemaphore.CurrentCount;\n\n    /// <summary>\n    /// Gets the number of slots currently available for queuing actions for execution through the bulkhead.","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Bulkhead/BulkheadPolicy.cs#L16-L52","documentation":"Thrown as ArgumentNullException(nameof(action)) from BulkheadPolicy.Implementation<TResult> when the action delegate passed to the execution method is null. This is the non-generic BulkheadPolicy's override that delegates to BulkheadEngine. The guard at line 32–34 fires before any semaphore interaction, so no resources are consumed.","triggerScenarios":"Calling policy.Execute(null) or policy.ExecuteAsync(null) on a non-generic BulkheadPolicy, or passing a lambda that resolves to null. The null check in Implementation<TResult> at BulkheadPolicy.cs:32–34 throws immediately.","commonSituations":"Passing a method reference that was never assigned (remains null). Conditional delegate construction where a branch returns null. Refactoring that accidentally removes the delegate body while keeping the call site.","solutions":["Ensure the delegate passed to Execute/ExecuteAsync is non-null before calling","If the action may legitimately be absent, guard the call site with a null check and skip execution","Use nullable reference type annotations to catch null delegates at compile time"],"exampleFix":"// before\nAction myAction = GetAction(); // may return null\npolicy.Execute(myAction); // ArgumentNullException\n\n// after\nAction myAction = GetAction();\nif (myAction is not null)\n{\n    policy.Execute(myAction);\n}","handlingStrategy":"validation","validationCode":"if (action is null)\n{\n    throw new InvalidOperationException(\"Action must be provided before execution.\");\n}\npolicy.Execute(action);","typeGuard":"public static bool IsExecutableDelegate(Action action) => action is not null;","tryCatchPattern":"try\n{\n    policy.Execute(action);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"action\")\n{\n    logger.LogError(\"Null action passed to bulkhead execution\");\n    throw;\n}","preventionTips":["Enable nullable reference types so the compiler flags null delegate assignments","Initialize delegate variables with a concrete value or throw at construction time","Avoid conditional delegate assignment without a default branch"],"tags":["bulkhead","null-argument","action","argument-validation"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}