{"record":{"id":"c94705d15746c1fc","repo":"git-ecosystem/git-credential-manager","slug":"state-value-cannot-be-null","errorCode":null,"errorMessage":"State value cannot be null.","messagePattern":"State value cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Core/GitStateValidation.cs","lineNumber":113,"sourceCode":"\n        if (key.StartsWith(Constants.CredentialProtocol.GcmStatePrefix, StringComparison.Ordinal))\n        {\n            throw new ArgumentException(\n                $\"State key cannot start with '{Constants.CredentialProtocol.GcmStatePrefix}'; \" +\n                \"the prefix is reserved and added automatically when state is emitted.\",\n                nameof(key));\n        }\n    }\n\n    /// <summary>\n    /// Throws <see cref=\"ArgumentException\"/> if <paramref name=\"value\"/> is\n    /// not a legal state entry value.\n    /// </summary>\n    public static void ValidateValue(string value)\n    {\n        if (value is null)\n        {\n            throw new ArgumentNullException(nameof(value), \"State value cannot be null.\");\n        }\n\n        foreach (char c in value)\n        {\n            if (c == LF || c == NUL)\n            {\n                throw new ArgumentException(\n                    \"State value cannot contain newline or NUL characters.\",\n                    nameof(value));\n            }\n        }\n    }\n}\n\n","sourceCodeStart":95,"sourceCodeEnd":128,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/GitStateValidation.cs#L95-L128","documentation":"This ArgumentNullException is raised by the validation helper GitStateValidation.ValidateValue (src/Core/GitStateValidation.cs:113), a generic guard called before any state entry value is stored or emitted. It fires when a caller passes a null string as the state entry value (the 'value' parameter). State values must be non-null so the serialized state payload stays well-formed; passing null indicates the caller failed to initialize or load the state value before persisting it.","triggerScenarios":"A caller invokes ValidateValue (directly or via state-entry write paths) with a state value that is null because it was never initialized, an optional lookup returned null, or a deserialization step produced a null value.","commonSituations":"Persisting Git credential-manager state entries where the value was not yet computed; copying state dictionaries where a key maps to null; constructing state payloads from configuration fields that are absent; tests exercising ValidateValue with null input.","solutions":["Initialize the state value to a non-null default (e.g. empty string) before calling ValidateValue or writing the state entry.","Skip persisting state entries whose value is null instead of passing them to the validator.","Fail fast upstream with a clearer, domain-specific error that names the missing state field.","Add a null check or null-forgiving/guard logic at the call site so null values never reach ValidateValue."],"exampleFix":"Ensure the state value is initialized before storing it: replace null with an empty string or a meaningful default, or skip the entry entirely. Example: if (value != null) { GitStateValidation.ValidateValue(value); state[key] = value; } — or throw a domain-specific error explaining which state field is missing.","handlingStrategy":"validation","validationCode":"if (value is null) return; // skip state entry, or use string.Empty","typeGuard":"static bool IsValidStateValue(string v) => v is not null;","tryCatchPattern":"try { response.SetState(key, value); }\ncatch (ArgumentNullException) { /* omit this state entry */ }","preventionTips":["Default optional values with ?? string.Empty before setting state.","Check lookups for null before mapping into state.","Document that values must be concrete strings, never null."],"tags":["csharp","null-argument","git-state-protocol"],"backgroundTag":"null-argument","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}