Visitar URL original
ScopeContext - Fix List capacity for GetAllNestedStates by jnyrup · Pull Request #6210 · NLog/NLog · GitHub
Skip to content

ScopeContext - Fix List capacity for GetAllNestedStates - #6210

Merged
snakefoot merged 1 commit into
NLog:devfrom
jnyrup:patch-1
Jun 7, 2026
Merged

snakefoot merged 1 commit into
NLog:devfrom
jnyrup:patch-1

Conversation

@jnyrup

@jnyrup jnyrup commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Parenthesize ?? as + binds stronger

Parenthesize `??` as `+` binds stronger
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c5532ba2-7853-465e-95c0-f52c9d086a05

📥 Commits

Reviewing files that changed from the base of the PR and between d6f69e6 and 6fe0877.

📒 Files selected for processing (1)
  • src/NLog/Internal/ScopeContextAsyncState.cs

Walkthrough

The PR fixes a single operator-precedence bug in ScopeContextNestedStateCollector.PushNestedState. Parentheses are adjusted in the List<object> capacity calculation so that + 1 applies to the null-coalesced nested-states count before the Math.Max comparison.

Changes

Capacity calculation operator-precedence fix

Layer / File(s) Summary
Capacity calculation operator-precedence fix
src/NLog/Internal/ScopeContextAsyncState.cs
The initial capacity expression corrects parenthesization so + 1 is applied to (_allNestedStates?.Count ?? 0) before passing to Math.Max(4, ...), fixing operator precedence.

🎯 1 (Trivial) | ⏱️ ~3 minutes

A little rabbit hops with glee,
Parentheses fixed, now all is clear!
Math.Max sees the +1 decree,
Operator precedence shines bright here. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing the List capacity calculation in the PushNestedState method.
Description check ✅ Passed The description is directly related to the changeset, explaining the technical reason for the fix (parenthesizing the null-coalescing operator due to operator precedence).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@sonarqubecloud

sonarqubecloud Bot commented Jun 7, 2026

Copy link
Copy Markdown

@snakefoot
snakefoot merged commit ce42142 into NLog:dev Jun 7, 2026
6 checks passed
@jnyrup
jnyrup deleted the patch-1 branch June 7, 2026 16:37
@snakefoot snakefoot changed the title Fix List capacity in PushNestedState Fix List capacity for ScopeContext GetAllNestedStates Jun 7, 2026
@snakefoot

Copy link
Copy Markdown
Contributor

Nicely spotted. Thank you for the contribution.

@snakefoot snakefoot added the enhancement Improvement on existing feature label Jun 7, 2026
@snakefoot snakefoot added this to the 6.1.4 milestone Jul 8, 2026
@snakefoot snakefoot changed the title Fix List capacity for ScopeContext GetAllNestedStates ScopeContext - Fix List capacity for GetAllNestedStates Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement on existing feature size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants