{"record":{"id":"3e96564663017e1c","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-specifier","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'specifier')","messagePattern":"Value cannot be null\\. \\(Parameter 'specifier'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationAttribute.cs","lineNumber":117,"sourceCode":"\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.AnnotationAttribute\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"AnnotationAttribute\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"specifier\">The annotation attribute specifier.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"specifier\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentException\">\n\t\t/// <paramref name=\"specifier\"/> contains illegal characters.\n\t\t/// </exception>\n\t\tpublic AnnotationAttribute (string specifier)\n\t\t{\n\t\t\tif (specifier == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (specifier));\n\n\t\t\tif (specifier.Length == 0)\n\t\t\t\tthrow new ArgumentException (\"Annotation attribute specifiers cannot be empty.\", nameof (specifier));\n\n\t\t\t// TODO: improve validation\n\t\t\tif (specifier.IndexOfAny (Wildcards) != -1)\n\t\t\t\tthrow new ArgumentException (\"Annotation attribute specifiers cannot contain '*' or '%'.\", nameof (specifier));\n\n\t\t\tSpecifier = specifier;\n\n\t\t\tif (specifier.EndsWith (\".shared\", StringComparison.Ordinal)) {\n\t\t\t\tName = specifier.Substring (0, specifier.Length - \".shared\".Length);\n\t\t\t\tScope = AnnotationScope.Shared;\n\t\t\t} else if (specifier.EndsWith (\".priv\", StringComparison.Ordinal)) {\n\t\t\t\tName = specifier.Substring (0, specifier.Length - \".priv\".Length);\n\t\t\t\tScope = AnnotationScope.Private;\n\t\t\t} else {\n\t\t\t\tScope = AnnotationScope.Both;","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationAttribute.cs#L99-L135","documentation":"The MailKit AnnotationAttribute constructor throws ArgumentNullException when the specifier string is null. An annotation attribute (e.g. \"/private\") must be a non-empty string identifying an IMAP ANNOTATE entry attribute, so a null value is rejected immediately as a programming error.","triggerScenarios":"Calling `new AnnotationAttribute(null)`, or building a specifier dynamically (e.g. from a variable that was never initialized) and passing it to the constructor or to APIs that construct AnnotationAttribute internally.","commonSituations":"Passing an uninitialized or null-returning string variable (e.g. a parsed config value that is missing) into the constructor; storing specifiers in a dictionary and fetching a key that does not exist.","solutions":["Ensure the specifier string is non-null before constructing AnnotationAttribute (check for null/whitespace).","Fix the upstream source of the string (config key, parsed IMAP attribute, dictionary lookup) so it always yields a value.","Wrap construction in a null check or use string.IsNullOrEmpty validation first."],"exampleFix":"// before\nvar attr = new AnnotationAttribute(config[\"Attribute\"]);\n// after\nvar name = config[\"Attribute\"];\nif (string.IsNullOrEmpty(name))\n    throw new InvalidOperationException(\"Annotation attribute not configured\");\nvar attr = new AnnotationAttribute(name);","handlingStrategy":"validation","validationCode":"if (specifier == null)\n    throw new InvalidOperationException(\"Annotation attribute specifier must be provided\");\nvar attr = new AnnotationAttribute(specifier);","typeGuard":"bool IsValidSpecifier(string s) => !string.IsNullOrEmpty(s) && s.IndexOfAny(new[] {'*','%'}) == -1;","tryCatchPattern":"try\n{\n    var attr = new AnnotationAttribute(specifier);\n}\ncatch (ArgumentNullException)\n{\n    // specifier was null — fix the caller/data source\n}\ncatch (ArgumentException ex)\n{\n    // empty or wildcard specifier\n}","preventionTips":["Never pass config or parsed values straight into AnnotationAttribute without a null/empty check.","Centralize specifier construction in one helper that validates once.","Treat specifiers as constants/named values where possible."],"tags":["mailkit","imap","annotations","argument-null"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}