{"record":{"id":"a04347d9b4ad02a7","repo":"jstedfast/MailKit","slug":"annotation-entry-paths-cannot-be-empty","errorCode":null,"errorMessage":"Annotation entry paths cannot be empty.","messagePattern":"Annotation entry paths cannot be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationEntry.cs","lineNumber":118,"sourceCode":"\t\t/// Used to get or set a private alternate subject on a message.\n\t\t/// </remarks>\n\t\tpublic static readonly AnnotationEntry PrivateAltSubject = new AnnotationEntry (\"/altsubject\", AnnotationScope.Private);\n\n\t\t/// <summary>\n\t\t/// An annotation entry for a shared alternate subject on a message.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Used to get or set a shared alternate subject on a message.\n\t\t/// </remarks>\n\t\tpublic static readonly AnnotationEntry SharedAltSubject = new AnnotationEntry (\"/altsubject\", AnnotationScope.Shared);\n\n\t\tstatic void ValidatePath (string path)\n\t\t{\n\t\t\tif (path == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (path));\n\n\t\t\tif (path.Length == 0)\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths cannot be empty.\", nameof (path));\n\n\t\t\tif (path[0] != '/' && path[0] != '*' && path[0] != '%')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must begin with '/'.\", nameof (path));\n\n\t\t\tif (path.Length > 1 && path[1] >= '0' && path[1] <= '9')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not include a part-specifier.\", nameof (path));\n\n\t\t\tif (path == \"*\" || path == \"%\")\n\t\t\t\treturn;\n\n\t\t\tchar pc = path[0];\n\n\t\t\tfor (int i = 1; i < path.Length; i++) {\n\t\t\t\tchar c = path[i];\n\n\t\t\t\tif (c > 127)\n\t\t\t\t\tthrow new ArgumentException ($\"Invalid character in annotation entry path: '{c}'.\", nameof (path));\n","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationEntry.cs#L100-L136","documentation":"AnnotationEntry.ValidatePath throws ArgumentException when the entry path is an empty string. IMAP annotation entry paths (RFC 5257) must start with '/' (or be a wildcard), so an empty path cannot identify any entry.","triggerScenarios":"Calling `new AnnotationEntry(\"\", scope)`, or passing an empty string produced by trimming/splitting user input or config values.","commonSituations":"Blank config entries for annotation paths; splitting a full annotation string (entry + attribute) and taking a segment that is empty.","solutions":["Validate with string.IsNullOrWhiteSpace(path) before constructing AnnotationEntry.","Ensure the path includes at least the leading '/' (e.g. \"/comment\").","Fix the producer of the empty string (trim, split, config read)."],"exampleFix":"// before\nvar entry = new AnnotationEntry(input, AnnotationScope.Shared);\n// after\nif (string.IsNullOrWhiteSpace(input))\n    throw new FormatException(\"Annotation entry path is required\");\nvar entry = new AnnotationEntry(input, AnnotationScope.Shared);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(path))\n    throw new FormatException(\"Annotation entry path must be non-empty and start with '/'\");\nvar entry = new AnnotationEntry(path, AnnotationScope.Shared);","typeGuard":"bool IsValidEntryPath(string p) => !string.IsNullOrEmpty(p) && (p[0] == '/' || p == \"*\" || p == \"%\");","tryCatchPattern":"try\n{\n    var entry = new AnnotationEntry(path, AnnotationScope.Shared);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"path\")\n{\n    // reject/repair empty path from config or input\n}","preventionTips":["Validate entry paths at config-load time.","Require the leading '/' in any user/config supplied path.","Check for empty segments when parsing combined entry/attribute strings."],"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"}