Fix null reference in recommendations #2984
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When loading the recommendations screen when it would contain multiple options:
I have no idea how I didn't encounter this during development of #2981, since that inherently required loading this screen with multiple options to test. Maybe there's a race condition?
Cause
Apparently
ListView.Items
can containnull
, specifically in theItemChecked
event while processing anAddRange
call. Upon reflection this is less surprising than at first blush, since on Windows these are wrappers around C++ components, which probably:Items
list with nulls, since it may be astd::vector
that has to copy its contents every time it is expandedItemChecked
for each in turn(Whereas I would expect a C# component to approach this as
foreach (...) { Items.Add(...); }
, which would never insert a null value.)The code from #2981 assumed
ListView.Items
would not contain nulls.Changes
Now
RecommendedModsListView_ItemChecked
skips nulls.