Skip to content

[Android] Exception thrown when give more than 5000 characters to the Text property of Entry. #30242

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

KarthikRajaKalaimani
Copy link
Contributor

Issue Details:

Exception thrown when give more than 5000 characters to the Text property of Entry on Android platform.

Root Cause:

When the Entry contains more than 5000 characters and the IsPassword property is mapped before the MaxLength property, the EditText input type is set to InputTypes.ClassText | InputTypes.TextVariationNormal. After the input type is updated, we attempts to restore the previous cursor position, which exceeds 5000 characters. This results in an IndexOutOfBoundsException during the selection process.

Description of Change:

To prevent the crash, I reordered the property mappers by applying the MaxLength mapper before the IsPassword mapper in EntryHandler

Tested the behavior in the following platforms.

  • Android
  • Windows
  • iOS
  • Mac

Reference:

N/A

Issues Fixed:

Fixes #30144

Screenshots

Before After
The application is crashed

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jun 26, 2025
@KarthikRajaKalaimani KarthikRajaKalaimani changed the title [Android] Exception thrown when give more than 5000 characters to the Text property of Entry on Android platform. [Android] Exception thrown when give more than 5000 characters to the Text property of Entry. Jun 26, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).


[Fact(DisplayName = "Android crash when Entry has more than 5000 characters")]
[Category(TestCategory.Entry)]
public async Task EntryWithLongTextAndIsPassword_DoesNotCrash()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to test the initialization, could you include another test updating the Text value?

public async Task UpdateTextWithTextLongerThanMaxLength()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to test the initialization, could you include another test updating the Text value?

public async Task UpdateTextWithTextLongerThanMaxLength()

I have added an additional test case that updates the Text value.

@KarthikRajaKalaimani KarthikRajaKalaimani marked this pull request as ready for review June 26, 2025 13:35
@KarthikRajaKalaimani KarthikRajaKalaimani requested a review from a team as a code owner June 26, 2025 13:35
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -23,14 +23,14 @@ public partial class EntryHandler : IEntryHandler
[nameof(IEntry.CharacterSpacing)] = MapCharacterSpacing,
[nameof(IEntry.ClearButtonVisibility)] = MapClearButtonVisibility,
[nameof(IEntry.Font)] = MapFont,
[nameof(IEntry.MaxLength)] = MapMaxLength,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about depending on the property mapper ordering. That feels a bit fragile.

One approach you can also take is multiple mappers that you pass into the main mapper ctor

I've also prompted copilot here to see what it thinks
#30302 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about depending on the property mapper ordering. That feels a bit fragile.

One approach you can also take is multiple mappers that you pass into the main mapper ctor

I've also prompted copilot here to see what it thinks #30302 (comment)

I reviewed the Copilot suggestion, and it appears to propose multiple fixes: reordering the mapping and applying a condition-based max length. Either approach should work if implemented. Would you like to implement both solutions, or just one?

I'm not quite clear on what you meant by, "you can also take multiple mappers that you pass into the main mapper constructor". Could you provide more insight?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#30330 (review)

I reviewed the Copilot-suggested fix and ensured that it works as expected. I then modified the fix and added a new test case to validate the MaxLength property behavior. The test has been written to run across all platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-entry Entry community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android crash when Entry has >5000 characters
3 participants