Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: Improve null safety in CorrelationId property getter - #581

#581
Merged
samtrion merged 1 commit into
maindailydevops/http.correlation:mainfrom
fix/httpcontext-null-handledailydevops/http.correlation:fix/httpcontext-null-handleCopy head branch name to clipboard
Mar 31, 2026
Merged

fix: Improve null safety in CorrelationId property getter#581
samtrion merged 1 commit into
maindailydevops/http.correlation:mainfrom
fix/httpcontext-null-handledailydevops/http.correlation:fix/httpcontext-null-handleCopy head branch name to clipboard

Conversation

@samtrion

@samtrion samtrion commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug Fixes
    • Improved robustness of correlation ID retrieval to prevent potential null reference exceptions.

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.
@samtrion samtrion self-assigned this Mar 31, 2026
@samtrion
samtrion requested a review from a team as a code owner March 31, 2026 14:03
@samtrion
samtrion requested review from Spacemonkay and removed request for a team March 31, 2026 14:03
@samtrion samtrion added state:ready for merge Indicates that a pull request has been reviewed and approved, and is ready to be merged into the mai type:bug Indicates an issue or flaw that needs to be fixed. labels Mar 31, 2026
@coderabbitai

coderabbitai Bot commented Mar 31, 2026

Copy link
Copy Markdown

Walkthrough

The CorrelationId property getter in HttpCorrelationAccessor was modified to access HttpContext using a null-conditional operator (?.) with force unwrap (!) instead of a non-null assertion operator, while maintaining the same string return behavior.

Changes

Cohort / File(s) Summary
Null-conditional operator refactor
src/NetEvolve.Http.Correlation.AspNetCore/HttpCorrelationAccessor.cs
Changed HttpContext!.TraceIdentifier to HttpContext?.TraceIdentifier! in property getter for safer null handling pattern.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

A hop toward safety, so neat and so fine,
From bang to the question, operators align,
Null-conditional whispers, then force-unwraps true,
One line, two operators—much safer to do! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: improving null safety in the CorrelationId property getter, which directly aligns with the changeset that updates the null-handling approach.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1c68b78 and c32be85.

📒 Files selected for processing (1)
  • src/NetEvolve.Http.Correlation.AspNetCore/HttpCorrelationAccessor.cs

@samtrion
samtrion merged commit d1dea43 into main Mar 31, 2026
12 checks passed
@samtrion
samtrion deleted the fix/httpcontext-null-handle branch March 31, 2026 14:06
@codecov

codecov Bot commented Mar 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.63%. Comparing base (adb916b) to head (c32be85).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
....Correlation.AspNetCore/HttpCorrelationAccessor.cs 0.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:ready for merge Indicates that a pull request has been reviewed and approved, and is ready to be merged into the mai type:bug Indicates an issue or flaw that needs to be fixed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.