-
Couldn't load subscription status.
- Fork 1.9k
[Android] Fix Entry/Editor crash when setting Text in TextChanged event handler #32005
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
base: main
Are you sure you want to change the base?
Changes from all commits
f30ccb7
63c11e9
dbaa1f1
8e36ffd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue32004"> | ||
| <VerticalStackLayout Padding="20" Spacing="10"> | ||
| <Label Text="Test Entry TextChanged crash" FontSize="18" FontAttributes="Bold"/> | ||
| <Label Text="1. Delete all text from the entry below" /> | ||
| <Label Text="2. App should not crash" /> | ||
|
|
||
| <Entry x:Name="CartonsEntry" | ||
| Text="0" | ||
| Keyboard="Numeric" | ||
| TextChanged="Quantity_TextChanged" | ||
| AutomationId="TestEntry" /> | ||
|
|
||
| <Label x:Name="StatusLabel" | ||
| Text="Status: Ready" | ||
| AutomationId="StatusLabel" /> | ||
| </VerticalStackLayout> | ||
| </ContentPage> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 32004, "Entry crashes when setting Text in TextChanged event handler", PlatformAffected.Android)] | ||
| public partial class Issue32004 : ContentPage | ||
| { | ||
| public Issue32004() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| private void Quantity_TextChanged(object sender, TextChangedEventArgs e) | ||
| { | ||
| // This reproduces the crash: when text is cleared (empty/null), | ||
| // setting the Text property causes a re-entrant TextWatcher callback | ||
| // while EmojiCompat is processing, leading to "end should be < than charSequence length" crash | ||
| if (string.IsNullOrEmpty(e.NewTextValue)) | ||
| { | ||
| ((Entry)sender).Text = "0"; | ||
| StatusLabel.Text = "Status: Reset to 0"; | ||
| } | ||
| else | ||
| { | ||
| StatusLabel.Text = $"Status: Text is '{e.NewTextValue}'"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #if ANDROID | ||
| using System.Threading.Tasks; | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues | ||
| { | ||
| public class Issue32004 : _IssuesUITest | ||
| { | ||
| public Issue32004(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Entry crashes when setting Text in TextChanged event handler"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Entry)] | ||
| public void EntryDoesNotCrashWhenSettingTextInTextChangedEvent() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is failing on Android. @copilot Review There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed the test crash by using |
||
| { | ||
| // Wait for the entry to be visible | ||
| App.WaitForElement("TestEntry"); | ||
|
|
||
| // Clear the entry text - this should trigger the TextChanged event | ||
| // which will set Text to "0", previously causing a crash | ||
| App.ClearText("TestEntry"); | ||
|
|
||
| // Wait a moment for the deferred text update to complete | ||
| Task.Delay(100).Wait(); | ||
|
|
||
| // If we reach here without crashing, the fix is working | ||
| // Verify that the status label updated | ||
| var statusText = App.WaitForElement("StatusLabel").GetText(); | ||
| Assert.That(statusText, Does.Contain("Reset to 0")); | ||
|
|
||
| // Verify the entry text was set to "0" | ||
| var entryText = App.WaitForElement("TestEntry").GetText(); | ||
| Assert.That(entryText, Is.EqualTo("0")); | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
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.
@copilot Tests should match the name of the issue being fixed
Can you please fix the name on this test and update any copilot instructions that led you to create this name incorrectly
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.
Renamed test files to match issue number #32004. Updated in commit 0e3c907.