{"record":{"id":"b102cc31508566ea","repo":"jstedfast/MailKit","slug":"keywords","errorCode":null,"errorMessage":"keywords","messagePattern":"keywords","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/AppendRequest.cs","lineNumber":81,"sourceCode":"\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"AppendRequest\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"message\">The message.</param>\n\t\t/// <param name=\"flags\">The message flags.</param>\n\t\t/// <param name=\"keywords\">The message keywords.</param>\n\t\t/// <exception cref=\"ArgumentNullException\">\n\t\t/// <para><paramref name=\"message\"/> is <see langword=\"null\" />.</para>\n\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"keywords\"/> is <see langword=\"null\" />.</para>\n\t\t/// </exception>\n\t\tpublic AppendRequest (MimeMessage message, MessageFlags flags, IEnumerable<string> keywords)\n\t\t{\n\t\t\tif (message == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (message));\n\n\t\t\tif (keywords == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (keywords));\n\n\t\t\tKeywords = keywords as ISet<string> ?? new HashSet<string> (keywords);\n\t\t\tMessage = message;\n\t\t\tFlags = flags;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"AppendRequest\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"AppendRequest\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"message\">The message.</param>\n\t\t/// <param name=\"flags\">The message flags.</param>\n\t\t/// <param name=\"internalDate\">The internal date of the message.</param>\n\t\t/// <exception cref=\"ArgumentNullException\">\n\t\t/// <paramref name=\"message\"/> is <see langword=\"null\" />.\n\t\t/// </exception>","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AppendRequest.cs#L63-L99","documentation":"MailKit's AppendRequest(MimeMessage, MessageFlags, IEnumerable<string>) constructor throws ArgumentNullException when the keywords collection is null. The constructor requires an enumerable set of IMAP keywords/flags to store on the appended message; a null collection is treated as a programming error rather than an empty set. Pass an empty collection if no keywords are intended.","triggerScenarios":"Calling new AppendRequest(message, flags, keywords) where keywords is a null IEnumerable<string> — e.g. a variable that was never assigned, a dictionary lookup that returned null, or a method that returns null when no keywords exist.","commonSituations":"Building APPEND requests from parsed user input or config where the keywords field is optional and left null; mapping legacy code that used null to mean 'no flags'; LINQ FirstOrDefault() returning null for an empty keyword set.","solutions":["Pass an empty collection (e.g. Array.Empty<string>() or new List<string>()) instead of null when there are no keywords.","Coalesce null at the call site: keywords ?? Array.Empty<string>().","Check the source of the keywords value (config, dictionary lookup, method return) and fix it to return an empty collection rather than null."],"exampleFix":"// before\nvar keywords = GetKeywords(); // returns null when none\nvar req = new AppendRequest(message, MessageFlags.Seen, keywords);\n\n// after\nvar req = new AppendRequest(message, MessageFlags.Seen, GetKeywords() ?? Array.Empty<string>());","handlingStrategy":"validation","validationCode":"if (keywords == null)\n    throw new InvalidOperationException(\"keywords must not be null; pass an empty collection\");\nvar req = new AppendRequest(message, flags, keywords);","typeGuard":"bool HasKeywords(IEnumerable<string> keywords) => keywords != null;","tryCatchPattern":"try\n{\n    var req = new AppendRequest(message, flags, keywords);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"keywords\")\n{\n    logger.LogError(ex, \"Null keywords passed to AppendRequest\");\n}","preventionTips":["Treat collections as empty-by-default: initialize keyword lists to empty, never null.","Use Array.Empty<string>() or Enumerable.Empty<string>() for the 'none' case.","Enable nullable reference types (C# 8+) so null flows are flagged at compile time."],"tags":["argument-null","imap","append","mailkit"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}