Fix bug in TabPageCollection.RemoveAt (#7837)#7911
Conversation
RussKie
left a comment
There was a problem hiding this comment.
Looks sensible.
Do you think it's possible to come up with a regression test that would simulate the original issue, so that we can verify the fix?
It's tricky - the sequence of events to get the collections out of sync is complicated. |
|
How did you initially observe the issue? How can we be sure we've fixed it? |
|
This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days. It will be closed if no further activity occurs within 7 days of this comment. |
|
@albahari , Can you respond to the questions above? PRs with inactivity will be closed automatically after 14days. |
|
Sorry for the delay - it took a while to get to a minimum repro. It's not until you subclass TabControl that the condition becomes apparent (or at least easy to reproduce). This discovery in itself has lead to finding a second bug. This second bug may in fact be a root cause (rendering the first bug fix redundant). Control.UpdateChildControlIndex starts with the following code: This check is the wrong way around. It should be: Fixing this bug means that the tabControl.Controls collection (appears to) stay in sync with TabControls._tabPages. Assuming that the two collections are intended to always stay in sync (and there are no other conditions that could result in these collections being ordered differently), the first bug fix becomes redundant. Here is a minimum repro. Note that it requires a running message loop, so TabPage can receive a WM_WINDOWPOSCHANGED message: How should I proceed with this? Create a new PR for the second bug fix? Note that while the original bug fix has virtually zero risk, the second bug fix could conceivably result in changed behavior in an (arguably obscure) scenario. Consider that someone instantiates the Control class directly: right now, the bug inappropriately short-circuits UpdateChildControlIndex when WM_WINDOWPOSCHANGED events are received. It might be prudent to mitigate that risk with this: |
|
Thank you @albahari for making time and sharing the findings here. We will review this and update you on next steps. |
|
@albahari , lets go ahead and update this PR with the new fix given current one is redundant after that. Also, make sure you add some unit tests / integration tests to cover the code path. |
|
I've updated the PR and added an integration test that fails without the bugfix. It doesn't make sense that the CI test would fail for X86 release on ActiveXFontMarshaler_RoundTripManagedFont() - perhaps this test needs to be repeated? |
lonitra
left a comment
There was a problem hiding this comment.
Test looks great! Just a few comments.
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/TabControlTests.cs
Outdated
Show resolved
Hide resolved
|
Looks like there is some trailing whitespace that is causing build to complain. It is difficult for me to see where on web, but if you build on command line (cd to winforms repo and type 'build'), the same errors should show and help point you to where the trailing whitespace is. |
Fixes #7837
Proposed changes
Customer Impact
Regression?
Risk
Test methodology
Microsoft Reviewers: Open in CodeFlow