{"record":{"id":"1518183bbf563ab3","repo":"Cysharp/UniTask","slug":"continuation","errorCode":null,"errorMessage":"continuation","messagePattern":"continuation","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs","lineNumber":263,"sourceCode":"                }\n\n                throw new InvalidOperationException(\"Critical: invalid exception type was held.\");\n            }\n\n            return result;\n        }\n\n        /// <summary>Schedules the continuation action for this operation.</summary>\n        /// <param name=\"continuation\">The continuation to invoke when the operation has completed.</param>\n        /// <param name=\"state\">The state object to pass to <paramref name=\"continuation\"/> when it's invoked.</param>\n        /// <param name=\"token\">Opaque value that was provided to the <see cref=\"UniTask\"/>'s constructor.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public void OnCompleted(Action<object> continuation, object state, short token /*, ValueTaskSourceOnCompletedFlags flags */)\n        {\n            if (continuation == null)\n            {\n                throw new ArgumentNullException(nameof(continuation));\n            }\n            ValidateToken(token);\n\n            /* no use ValueTaskSourceOnCOmpletedFlags, always no capture ExecutionContext and SynchronizationContext. */\n\n            /*\n                PatternA: GetStatus=Pending => OnCompleted => TrySet*** => GetResult\n                PatternB: TrySet*** => GetStatus=!Pending => GetResult\n                PatternC: GetStatus=Pending => TrySet/OnCompleted(race condition) => GetResult\n                C.1: win OnCompleted -> TrySet invoke saved continuation\n                C.2: win TrySet -> should invoke continuation here.\n            */\n\n            // not set continuation yet.\n            object oldContinuation = this.continuation;\n            if (oldContinuation == null)\n            {\n                continuationState = state;","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs#L245-L281","documentation":"Thrown by UniTaskCompletionSourceCore<TResult>.OnCompleted when the continuation argument is null. The method registers a callback to invoke when the operation completes; a null callback would cause a NullReferenceException at completion time. The guard is a standard null-argument check at the registration boundary.","triggerScenarios":"Calling OnCompleted(null, state, token) on a UniTaskCompletionSourceCore. This typically happens when manually wiring continuations or in custom IUniTaskSource adapters that pass through a null continuation.","commonSituations":"Custom awaiter or IUniTaskSource implementations that forward a continuation parameter that may be null. Interop layers between UniTask and other async patterns that fail to provide a continuation.","solutions":["Null-check the continuation before calling OnCompleted","Ensure custom awaiter implementations always provide a valid Action<object> continuation","If you use the await keyword, the compiler generates the continuation for you — avoid manual OnCompleted calls"],"exampleFix":"// before\nsource.OnCompleted(null, state, token); // throws\n\n// after\nsource.OnCompleted(myContinuation ?? (_ => { }), state, token);","handlingStrategy":"validation","validationCode":"if (continuation != null)\n{\n    source.OnCompleted(continuation, state, token);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer await over manual OnCompleted calls","Null-check continuation arguments in custom awaiter implementations","Use the compiler-generated await pattern to avoid null continuation bugs"],"tags":["unitask","completion-source","null-argument","unity","csharp"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}