Uh oh!
There was an error while loading. Please reload this page.
Ensure Bind can handle null from GetSection - #92384
Conversation
IConfiguration instances may return a null value from GetSection. We were not handling this and would throw a NullReferenceException.
ghost
commented
Sep 20, 2023
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsFixes #92213 IConfiguration instances may return a null value from GetSection. We were not handling this and would throw a NullReferenceException.
|
| return; | ||
| } | ||
| if (config == null) |
There was a problem hiding this comment.
Previously the entire block below was wrapped in a null check - 35f043f#diff-2e6f75e1d4f577e1c8c1b6a32d158ce7812a38ad8fcd3b4d762157b92c03e890L308-R315
Since this method already has multiple returns, I find it more readable to early-exit rather than count curly-brackets/indentation.
RussKie
commented
Sep 21, 2023
Thank you! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
tarekgh
left a comment
There was a problem hiding this comment.
Added minor comment/suggestion, LGTM otherwise. Thanks for fixing this.
Uh oh!
There was an error while loading. Please reload this page.
ericstj
commented
Sep 21, 2023
@RussKie - if you wanted to workaround this you can register a mock section as the default return value for mockConfSection.Setup(m =>m.GetSection(It.IsAny<string>())).Returns(emptySection.Object);That would ensure that GetSection doesn't return |
RussKie
commented
Sep 21, 2023
👍 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ericstj
commented
Sep 22, 2023
Remaining legs are outer loop build incorrectly triggered for all PRs |
ericstj
commented
Sep 22, 2023
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6268341143 |
ericstj
commented
Sep 22, 2023
/backport to release/8.0-rc2 |
Started backporting to release/8.0-rc2: https://github.com/dotnet/runtime/actions/runs/6275041479 |
Fixes#92213
IConfiguration instances may return a null value from GetSection. We were not handling this and would throw a NullReferenceException.