-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix nullability in IOptionsMonitor
#65225
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
Conversation
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsQuick follow-up for #63767 While annotating
|
src/libraries/Microsoft.Extensions.Options/ref/Microsoft.Extensions.Options.cs
Show resolved
Hide resolved
eerhardt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
deeprobin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Is that the only case? Is it likely others have implemented this to return null? Do we document it as possibly returning null? If this is an isolated case, seems better to fix that one occurrence to not return null; basically it was violating the implicit contract and we're fixing it. It's weird / unexpected for something that returns IDisposable to return null. It could just return a dummy singleton that nops. |
|
@stephentoub documentation doesn't say about nullability of the result, but all
Not sure about other places that implement |
Meaning all consumers do null checks on the result? Sounds then like nullable is the right answer. Thanks |
Yes. Every place I inspected does null checks before disposing the result. Examples:
runtime/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs Line 189 in 9293aab
|
|
Off-topic: @eerhardt could you please tell, how do you do code previews like this? |
It only works for code in the same repo. But the way I do it is using Then when you paste that link into GH, it shows the code. runtime/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs Lines 186 to 191 in 9293aab
Your links above are using a branch name, not a commit hash. So in the future, when the code changes, those links will point to different code, whatever happens to be at that line in the future. Using "permalink", or commit hash links, will always point to that code, even if it is deleted in the future. |


Quick follow-up to #63767
While annotating
Microsoft.Extensions.Logging, it turns out thatIOptionsMonitor.OnChangecould returnnull:https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Logging/src/StaticFilterOptionsMonitor.cs#L16