{"record":{"id":"0126e2054f38119a","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-rights","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'rights')","messagePattern":"Value cannot be null\\. \\(Parameter 'rights'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/AccessRights.cs","lineNumber":160,"sourceCode":"\t\tpublic bool Add (char right)\n\t\t{\n\t\t\treturn Add (new AccessRight (right));\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Add the rights specified by the characters in the given string.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Adds the rights specified by the characters in the given string.\n\t\t/// </remarks>\n\t\t/// <param name=\"rights\">The rights.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"rights\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tpublic void AddRange (string rights)\n\t\t{\n\t\t\tif (rights == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (rights));\n\n\t\t\tfor (int i = 0; i < rights.Length; i++)\n\t\t\t\tAdd (new AccessRight (rights[i]));\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Add the range of specified rights.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Adds the range of specified rights.\n\t\t/// </remarks>\n\t\t/// <param name=\"rights\">The rights.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"rights\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tpublic void AddRange (IEnumerable<AccessRight> rights)\n\t\t{\n\t\t\tif (rights == null)","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AccessRights.cs#L142-L178","documentation":"AccessRights.AddRange(string rights) parses a string of single-character access rights (e.g. \"lrs\") and adds each as an AccessRight. A null rights string throws ArgumentNullException(nameof(rights)) at MailKit/AccessRights.cs:160. The guard exists because there is no meaningful way to interpret a null rights specification.","triggerScenarios":"Calling rights.AddRange(null) with the string overload — e.g. a null string from a parsed server response, config value, or an uninitialized variable.","commonSituations":"Building IMAP ACL rights from a decoded GETACL response where the rights token was missing; passing a settings value that was never configured.","solutions":["Pass a valid rights string (e.g. \"lrs\") to AddRange.","Ensure the code producing the rights string cannot return null; default to string.Empty when absent.","Check the argument for null before calling AddRange and skip or substitute a default set."],"exampleFix":"// before\nstring aclRights = GetRightsFromConfig(); // may be null\naccessRights.AddRange(aclRights);\n\n// after\nstring aclRights = GetRightsFromConfig() ?? string.Empty;\nif (aclRights.Length > 0)\n    accessRights.AddRange(aclRights);","handlingStrategy":"validation","validationCode":"if (rights != null)\n    accessRights.AddRange(rights);","typeGuard":"bool HasRights(string rights) => !string.IsNullOrEmpty(rights);","tryCatchPattern":"try\n{\n    accessRights.AddRange(rights);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"rights\")\n{\n    logger.LogWarning(\"No rights string available; using empty rights\");\n}","preventionTips":["Default rights strings from config/server responses with ?? string.Empty","Validate parsed ACL tokens for null before adding","Treat missing rights as an explicit empty set rather than null"],"tags":["argument-null","imap","acl","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"}