fix: Improve null safety in CorrelationId property getter - #581
#581fix: Improve null safety in CorrelationId property getter#581samtrion merged 1 commit intomaindailydevops/http.correlation:mainfrom fix/httpcontext-null-handledailydevops/http.correlation:fix/httpcontext-null-handleCopy head branch name to clipboard
Conversation
Updated the CorrelationId getter to use the null-conditional operator when accessing HttpContext.TraceIdentifier. This prevents potential NullReferenceExceptions if HttpContext is null, improving the robustness of the accessor.
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/NetEvolve.Http.Correlation.AspNetCore/HttpCorrelationAccessor.cs`:
- Line 18: The CorrelationId getter currently uses the null-forgiving operator
on _httpContextAccessor.HttpContext?.TraceIdentifier which can still yield null;
update the CorrelationId property (and assignment to _correlationId) to coalesce
the TraceIdentifier to a non-null fallback when HttpContext is absent (for
example generate a new GUID string or use a stable non-empty value) so the
IHttpCorrelationAccessor.CorrelationId contract is never violated; specifically
change the getter that references _correlationId and
_httpContextAccessor.HttpContext?.TraceIdentifier to use null-coalescing with a
safe fallback.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6ddb2545-467c-46b4-9a6d-69fa727c2d69
📒 Files selected for processing (1)
src/NetEvolve.Http.Correlation.AspNetCore/HttpCorrelationAccessor.cs
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #581 +/- ##
==========================================
- Coverage 98.22% 97.63% -0.60%
==========================================
Files 18 18
Lines 169 169
Branches 22 22
==========================================
- Hits 166 165 -1
Misses 2 2
- Partials 1 2 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Updated the CorrelationId getter to use the null-conditional operator when accessing HttpContext.TraceIdentifier. This prevents potential NullReferenceExceptions if HttpContext is null, improving the robustness of the accessor.
Summary by CodeRabbit