{"record":{"id":"87ad7f735a99c208","repo":"jstedfast/MailKit","slug":"an-annotation-entry-cannot-be-empty","errorCode":null,"errorMessage":"An annotation entry cannot be empty.","messagePattern":"An annotation entry cannot be empty\\.","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationEntry.cs","lineNumber":430,"sourceCode":"\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Parses an annotation entry.\n\t\t/// </remarks>\n\t\t/// <param name=\"entry\">The annotation entry.</param>\n\t\t/// <returns>The parsed annotation entry.</returns>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"entry\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.FormatException\">\n\t\t/// <paramref name=\"entry\"/> does not conform to the annotation entry syntax.\n\t\t/// </exception>\n\t\tpublic static AnnotationEntry Parse (string entry)\n\t\t{\n\t\t\tif (entry == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (entry));\n\n\t\t\tif (entry.Length == 0)\n\t\t\t\tthrow new FormatException (\"An annotation entry cannot be empty.\");\n\n\t\t\tif (entry[0] != '/' && entry[0] != '*' && entry[0] != '%')\n\t\t\t\tthrow new FormatException (\"An annotation entry must begin with a '/' character.\");\n\n\t\t\tvar scope = AnnotationScope.Both;\n\t\t\tint startIndex = 0, endIndex;\n\t\t\tstring? partSpecifier = null;\n\t\t\tvar component = 0;\n\t\t\tvar pc = entry[0];\n\t\t\tstring path;\n\n\t\t\tfor (int i = 1; i < entry.Length; i++) {\n\t\t\t\tchar c = entry[i];\n\n\t\t\t\tif (c >= '0' && c <= '9' && pc == '/') {\n\t\t\t\t\tif (component > 0)\n\t\t\t\t\t\tthrow new FormatException (\"Invalid annotation entry.\");\n","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationEntry.cs#L412-L448","documentation":"Validation inside AnnotationEntry.Parse: after the null check, an empty string is rejected with FormatException because an annotation entry must contain a mailbox path, entry name and value; there is nothing to parse from an empty string.","triggerScenarios":"Calling AnnotationEntry.Parse(\"\") or Parse of a string that trimmed to empty — e.g. a config value that is an empty string, or string.Split producing empty tokens fed to Parse.","commonSituations":"Empty environment/config values, splitting an entry list on separators that yields blank items, initializing strings to \"\" and never populating them.","solutions":["Skip empty strings before calling Parse (filter after splitting)","Validate entry.Length > 0 and handle the empty case explicitly","Fix the source so a real entry string is provided"],"exampleFix":"// before\nforeach (var s in raw.Split (','))\n    entries.Add (AnnotationEntry.Parse (s));\n// after\nforeach (var s in raw.Split (',', StringSplitOptions.RemoveEmptyEntries))\n    entries.Add (AnnotationEntry.Parse (s));","handlingStrategy":"validation","validationCode":"var tokens = raw.Split (',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);\nforeach (var t in tokens)\n    entries.Add (AnnotationEntry.Parse (t));","typeGuard":"bool CanParse (string? entry) => !string.IsNullOrEmpty (entry);","tryCatchPattern":"try {\n    var annotation = AnnotationEntry.Parse (entry);\n} catch (FormatException) {\n    logger.LogWarning (\"Skipped empty or invalid annotation entry\");\n}","preventionTips":["Use RemoveEmptyEntries when splitting entry lists","Validate non-empty before Parse when data may be blank","Distinguish 'absent' (null) from 'empty' ('') in your config schema"],"tags":["imap","annotation","parsing","empty-input"],"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"}