A small PR review is needed in the mailing preparation service. After the changes, the team noticed two symptoms: when rechecking the plan, some addresses suddenly “disappear,” and the final recipient list sometimes changes after external modifications to the source collection. You need to find the causes and describe what exactly must be fixed.
Context and requirements:
Build method API contract:
IEnumerable<string> recipients;DispatchPlan object;Trim();DispatchPlan.Recipients must be safe to read multiple times and must not depend on later changes to the input collection after returning from Build;DispatchPlan.Total must match the actual number of recipients in the plan.How to reproduce the observed problems:
List<string> with values " alice@example.com ", "", "Alice@example.com", "bob@example.com".Build and save the result.plan.Recipients twice in a row: on the second pass, the contents no longer match the first.Build, add a new address to the source list and enumerate plan.Recipients again: the result changes even though the plan has already been built.Assumptions:
DispatchPlan may call Count(), ToArray(), and iterate over Recipients multiple times.You need to assess exactly this diff: what defects it contains, why they appear, and how to fix the code correctly without changing the public contract.
C# 12, .NET 8 SDK 8.0.x, System.Linq from the BCL. A net8.0 project with nullable enabled is sufficient. No additional configuration is required.
Use line comments to explain the problem, its impact, the fix and how to test it.