{"record":{"id":"e2e6de79b6d43b57","repo":"Cysharp/UniTask","slug":"handler","errorCode":null,"errorMessage":"handler","messagePattern":"handler","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/TriggerEvent.cs","lineNumber":173,"sourceCode":"                }\n\n                var next = h == iteratingNode ? h.Next : iteratingNode;\n                iteratingNode = null;\n                Remove(h);\n                h = next;\n            }\n\n            iteratingNode = null;\n            if (iteratingHead != null)\n            {\n                Add(iteratingHead);\n                iteratingHead = null;\n            }\n        }\n\n        public void Add(ITriggerHandler<T> handler)\n        {\n            if (handler == null) throw new ArgumentNullException(nameof(handler));\n\n            // zero node.\n            if (head == null)\n            {\n                head = handler;\n                return;\n            }\n\n            if (iteratingNode != null)\n            {\n                if (iteratingHead == null)\n                {\n                    iteratingHead = handler;\n                    return;\n                }\n\n                var last = iteratingHead.Prev;\n                if (last == null)","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/TriggerEvent.cs#L155-L191","documentation":"Thrown by TriggerEvent<T>.Add when the handler argument is null. UniTask requires a valid ITriggerHandler<T> because the trigger maintains a doubly-linked list of handlers with Prev/Next pointers; a null node would cause NullReferenceException during iteration. This is a fail-fast guard at the API boundary.","triggerScenarios":"Calling triggerEvent.Add(null) directly, or passing a handler variable that was never assigned or was conditionally set to null before the Add call.","commonSituations":"Registering a handler from a factory method that can return null, or after a conditional check that skipped handler creation. Subscribing in a loop where some iterations have no handler to add.","solutions":["Null-check the handler before calling Add","Ensure the factory or builder that produces the handler never returns null","Use a guard clause: if (handler != null) triggerEvent.Add(handler);"],"exampleFix":"// before\ntriggerEvent.Add(maybeNullHandler);\n\n// after\nif (maybeNullHandler != null)\n{\n    triggerEvent.Add(maybeNullHandler);\n}","handlingStrategy":"validation","validationCode":"if (handler != null)\n{\n    triggerEvent.Add(handler);\n}","typeGuard":"static bool IsValidHandler<T>(ITriggerHandler<T> handler) => handler != null;","tryCatchPattern":null,"preventionTips":["Always null-check handlers before calling Add","Ensure handler factory methods never return null","Use a helper extension method that does the null check internally"],"tags":["unitask","trigger-event","null-argument","unity","csharp"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}