{"record":{"id":"17751ff2fd0871c0","repo":"App-vNext/Polly","slug":"value-cannot-be-null-17751f","errorCode":null,"errorMessage":"Value cannot be null.","messagePattern":"Value cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Bulkhead/BulkheadSyntax.cs","lineNumber":65,"sourceCode":"    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">maxParallelization;Value must be greater than zero.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\">maxQueuingActions;Value must be greater than or equal to zero.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onBulkheadRejected\"/> is <see langword=\"null\"/>.</exception>\n    public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions, Action<Context> onBulkheadRejected)\n    {\n        if (maxParallelization <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxParallelization), \"Value must be greater than zero.\");\n        }\n\n        if (maxQueuingActions < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), \"Value must be greater than or equal to zero.\");\n        }\n\n        if (onBulkheadRejected == null)\n        {\n            throw new ArgumentNullException(nameof(onBulkheadRejected));\n        }\n\n        return new BulkheadPolicy(\n            maxParallelization,\n            maxQueuingActions,\n            onBulkheadRejected);\n    }\n\n    private static void EmptyAction(Context context)\n    {\n        // No-op\n    }\n}\n","sourceCodeStart":47,"sourceCodeEnd":79,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Bulkhead/BulkheadSyntax.cs#L47-L79","documentation":"Thrown as ArgumentNullException(nameof(onBulkheadRejected)) from the non-generic Policy.Bulkhead(maxParallelization, maxQueuingActions, onBulkheadRejected) overload when the rejection callback is null. The guard at BulkheadSyntax.cs:65–68 fires at construction time. The callback is invoked when the bulkhead rejects execution due to overflow.","triggerScenarios":"Calling Policy.Bulkhead(maxParallelization, maxQueuingActions, null) — passing null as the onBulkheadRejected parameter. The guard at BulkheadSyntax.cs:65 fires before the BulkheadPolicy is constructed.","commonSituations":"Using the three-parameter overload without needing a rejection callback (use the two-parameter overload instead). Passing a callback variable that was conditionally assigned and ended up null.","solutions":["Use the two-parameter Policy.Bulkhead(maxParallelization, maxQueuingActions) overload if no rejection callback is needed","Pass a no-op lambda: _ => { } as the callback","Ensure the callback variable is non-null before passing it"],"exampleFix":"// before\nAction<Context> onReject = condition ? ctx => LogReject(ctx) : null;\nvar policy = Policy.Bulkhead(10, 5, onReject); // throws if condition is false\n\n// after\nvar policy = Policy.Bulkhead(10, 5); // use two-parameter overload\n// or:\nAction<Context> onReject = condition ? ctx => LogReject(ctx) : _ => { };\nvar policy = Policy.Bulkhead(10, 5, onReject);","handlingStrategy":"validation","validationCode":"Action<Context> safeOnReject = onBulkheadRejected ?? (_ => { });\nvar policy = Policy.Bulkhead(maxParallelization, maxQueuingActions, safeOnReject);","typeGuard":"public static bool IsNonNullCallback(Action<Context> callback) => callback is not null;","tryCatchPattern":null,"preventionTips":["Use the two-parameter Policy.Bulkhead(maxParallelization, maxQueuingActions) overload when no callback is needed","Coalesce null callbacks with a no-op lambda at the call site","Prefer the simpler overload unless rejection logging is explicitly required"],"tags":["bulkhead","null-argument","configuration","callback","construction"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}