Repository navigation
Conversation
Use null-coalescing assignment in WrapperBase.WrappedElement getter to ensure the field is only read once during retrieval, avoiding race conditions where OnElementReplaced clears the field before the return. Closes bUnit-dev#1937
Collaborator
|
Looking good - let's wait what CI/CD is saying and then get that in. |
linkdotnet
reviewed
Oct 18, 2026
|
|
||
| ### Fixed | ||
|
|
||
| - `WrapperBase<TElement>.WrappedElement` could return `null` and throw `NullReferenceException` when an element was accessed concurrently with component re-renders. Reported by [@psu-prog](https://github.com/psu-prog) in #1937. Fixed by [@Nacl-HCl](https://github.com/Nacl-HCl). |
Collaborator
There was a problem hiding this comment.
Using < and > leads to issues (see other generic usages) as we "merge" that inside the csproj - so it leads to malformed csproj file. Either drop the < > or use < stuff
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull request description
Fixes a race condition in
WrapperBase<TElement>.WrappedElementwhere an element returned byFind()could returnnulland throw aNullReferenceExceptionon member access when the component re-renders on another thread at the same time (e.g. from a background timer or asynchronous event).Cause
The getter previously read the
elementfield twice:`csharp
if (element is null)
element = elementFactory.GetElement();
return element;
WhenOnElementReplacedresetelementtonullbetween the check and the return statement, the getter returnednull`.Fix
Changed the getter to evaluate via null-coalescing assignment
element ??= elementFactory.GetElement<TElement>(), which ensures the reference is evaluated once and never returnsnull. Also updated the verified generator snapshot and added a concurrent regression test.Closes #1937
PR meta checklist
mainbranch for codeCode PR specific checklist