{"record":{"id":"8d910c79d99be7e2","repo":"jstedfast/MailKit","slug":"visitor-bodypartmultipart","errorCode":null,"errorMessage":"visitor","messagePattern":"visitor","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/BodyPartMultipart.cs","lineNumber":156,"sourceCode":"\t\t/// <summary>\n\t\t/// Dispatches to the specific visit method for this MIME body part.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// This default implementation for <see cref=\"MailKit.BodyPart\"/> nodes\n\t\t/// calls <see cref=\"MailKit.BodyPartVisitor.VisitBodyPart\"/>. Override this\n\t\t/// method to call into a more specific method on a derived visitor class\n\t\t/// of the <see cref=\"MailKit.BodyPartVisitor\"/> class. However, it should still\n\t\t/// support unknown visitors by calling\n\t\t/// <see cref=\"MailKit.BodyPartVisitor.VisitBodyPart\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"visitor\">The visitor.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"visitor\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tpublic override void Accept (BodyPartVisitor visitor)\n\t\t{\n\t\t\tif (visitor == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (visitor));\n\n\t\t\tvisitor.VisitBodyPartMultipart (this);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Encodes the <see cref=\"BodyPart\"/> into the <see cref=\"System.Text.StringBuilder\"/>.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Encodes the <see cref=\"BodyPart\"/> into the <see cref=\"System.Text.StringBuilder\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"builder\">The string builder.</param>\n\t\tprotected override void Encode (StringBuilder builder)\n\t\t{\n\t\t\tEncode (builder, BodyParts);\n\t\t\tbuilder.Append (' ');\n\t\t\tEncode (builder, ContentType.MediaSubtype);\n\t\t\tbuilder.Append (' ');\n\t\t\tEncode (builder, ContentType.Parameters);","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/BodyPartMultipart.cs#L138-L174","documentation":"BodyPartMultipart.Accept(BodyPartVisitor) throws ArgumentNullException when the visitor parameter is null. Accept dispatches to visitor.VisitBodyPartMultipart, which requires a live visitor object; a null argument would crash inside the call, so the method validates immediately. Every concrete BodyPart subtype follows this same pattern.","triggerScenarios":"Calling multipartBodyPart.Accept(null) while walking a parsed BODYSTRUCTURE tree, usually because the visitor variable was never assigned or a factory method returned null.","commonSituations":"Generic traversal code that receives the visitor as a parameter itself (possibly null from an outer caller) and forwards it to Accept without checking.","solutions":["Ensure a non-null BodyPartVisitor is constructed before traversing.","Add a null check before calling Accept when the visitor is optional in your flow.","Validate visitor at your own public API boundary so nulls never reach library calls."],"exampleFix":"// before\nforeach (var part in bodyParts)\n    part.Accept(visitor); // may be null\n// after\nArgumentNullException.ThrowIfNull(visitor);\nforeach (var part in bodyParts)\n    part.Accept(visitor);","handlingStrategy":"validation","validationCode":"if (visitor is null)\n    return; // or create a default visitor\nmultipart.Accept(visitor);","typeGuard":"bool CanTraverse(BodyPart part, BodyPartVisitor? visitor) => part is BodyPartMultipart && visitor is not null;","tryCatchPattern":"try {\n    multipart.Accept(visitor);\n} catch (ArgumentNullException ex) when (ex.ParamName == \"visitor\") {\n    visitor = new DefaultBodyPartVisitor();\n    multipart.Accept(visitor);\n}","preventionTips":["Pass the visitor through traversal code as a non-nullable parameter.","Construct a default/no-op visitor rather than leaving the variable null.","Add a debug assert or guard clause in your traversal helper before calling Accept."],"tags":["null-reference","visitor-pattern","argument-validation","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-16T04:17:20.429Z"}