Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ResilienceProperties to correctly handle null values #2300

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iliar-turdushev
Copy link

The PR adds logic to handling cases when the value being requested from ResilienceProperties is null.

Fixes #2299

Adds logic handling a case when the value being requested is null
}
else if (val == null)
{
value = default!;
Copy link
Author

@iliar-turdushev iliar-turdushev Sep 20, 2024

Choose a reason for hiding this comment

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

We have to use a null-forgiving operator here, otherwise - the compiler generates a warning https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings#nonnullable-reference-not-initialized.

@@ -20,10 +20,18 @@ public sealed class ResilienceProperties
/// <returns>True, if a property was retrieved.</returns>
public bool TryGetValue<TValue>(ResiliencePropertyKey<TValue> key, [MaybeNullWhen(false)] out TValue value)
Copy link
Member

Choose a reason for hiding this comment

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

Assuming a null value is permissible in the first place, doesn't that mean this annotation is wrong? Feels to me that if a null value is legal then we shouldn't need to use ! as the compiler should already consider it a valid possibility.

src/Polly.Core/ResilienceProperties.cs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@1c6f3aa). Learn more about missing BASE report.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2300   +/-   ##
=======================================
  Coverage        ?   85.39%           
=======================================
  Files           ?      313           
  Lines           ?     7461           
  Branches        ?     1126           
=======================================
  Hits            ?     6371           
  Misses          ?      745           
  Partials        ?      345           
Flag Coverage Δ
windows 85.39% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: ResilienceProperties works incorrectly when the value requested by a key is null
2 participants