{"record":{"id":"1fe229f5ddf9762c","repo":"jstedfast/MailKit","slug":"annotation-attribute-specifiers-cannot-be-empty","errorCode":null,"errorMessage":"Annotation attribute specifiers cannot be empty.","messagePattern":"Annotation attribute specifiers cannot be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationAttribute.cs","lineNumber":120,"sourceCode":"\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;\n\t\t\t\tName = specifier;\n\t\t\t}\n\t\t}","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationAttribute.cs#L102-L138","documentation":"The AnnotationAttribute constructor throws ArgumentException when the specifier is an empty string. IMAP annotation attributes must have at least one character (e.g. \"/private\" or \"value\"), so an empty specifier is invalid.","triggerScenarios":"Calling `new AnnotationAttribute(\"\")` directly, or passing the result of a substring/split operation that produced an empty string (e.g. specifier.Split('/')[1] when the string has no second segment).","commonSituations":"Parsing attribute names from a settings file or user input where the value is blank; trimming a specifier down to nothing; splitting strings without guarding for missing segments.","solutions":["Check string.IsNullOrWhiteSpace(specifier) before constructing AnnotationAttribute.","Validate the full specifier format (e.g. \"/private\", \"/shared\", \"value.privacy\") before construction.","Correct whatever produced the empty string (split, trim, config read)."],"exampleFix":"// before\nvar attr = new AnnotationAttribute(userInput.Trim());\n// after\nvar trimmed = userInput.Trim();\nif (trimmed.Length == 0)\n    throw new FormatException(\"Annotation attribute specifier is required\");\nvar attr = new AnnotationAttribute(trimmed);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(specifier))\n    throw new InvalidOperationException(\"Annotation attribute specifier must be non-empty\");\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 (ArgumentException ex) when (ex.ParamName == \"specifier\")\n{\n    // log and use a corrected/default specifier\n}","preventionTips":["Trim and check IsNullOrWhiteSpace before constructing.","When splitting strings, verify segment count before indexing.","Validate specifiers at configuration load time, not at use time."],"tags":["mailkit","imap","annotations","empty-string"],"backgroundTag":"empty-required-field","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"}