fix: guard against null source in SingleOrDefaultIfMultiple - #147
Conversation
SingleOrDefaultIfMultiple called source.GetEnumerator() directly, so a null argument surfaced as a NullReferenceException. Every other entry point in this file (Only / OnlyOrDefault, via TryOnly) validates the argument with Guard.NotNull and throws ArgumentNullException. Add the same guard so the null-argument contract is consistent across EnumerableExtensions.Single. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (7)**/*.{ts,tsx,js,jsx,cs,py}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.cs📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
src/ANcpLua.Roslyn.Utilities/**/*.{cs,csproj}📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/**/*.cs📄 CodeRabbit inference engine (Custom checks)
Files:
⚙️ CodeRabbit configuration file
Files:
src/**/*.{cs,js,ts,py}📄 CodeRabbit inference engine (Custom checks)
Files:
**⚙️ CodeRabbit configuration file
Files:
src/ANcpLua.Roslyn.Utilities/**⚙️ CodeRabbit configuration file
Files:
🔇 Additional comments (1)
Summary by CodeRabbit
WalkthroughAdds a Null Guard Addition
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (7 passed)
Comment |
SingleOrDefaultIfMultiple<T>callssource.GetEnumerator()without validatingsource, so passingnullthrows aNullReferenceException.Every other public entry point in
EnumerableExtensions.Single—Only,Only(predicate),OnlyOrDefault,OnlyOrDefault(predicate)— routes throughTryOnly, which callsGuard.NotNull(source)and throws a cleanArgumentNullException. This makesSingleOrDefaultIfMultiplethe odd one out.This adds the same
Guard.NotNull(source)guard so the null-argument contract is consistent across the file. No behavior change for non-null inputs.