maui icon indicating copy to clipboard operation
maui copied to clipboard

Java.Lang.IndexOutOfBoundsException: 'setSpan ( ... ) ends beyond length

Open Delphinidae84 opened this issue 1 year ago • 7 comments

Description

Entry-Elements cause a Java.Lang.IndexOutOfBoundsException when the binding contains more characters than specified by the MaxLength-Attribute.

View

<?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"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:local="clr-namespace:maui_issue_samples"
             x:Class="maui_issue_samples.MainPage">
    <ContentPage.BindingContext>
        <local:DemoViewModel />
    </ContentPage.BindingContext>

    <Entry Text="{Binding Text}" MaxLength="2"/>
</ContentPage>

ViewModel


using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace maui_issue_samples
{
    class DemoViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;

        public String Text
        {
            get => _text;
            set
            {
                if (value != _text)
                {
                    _text = value;
                    OnPropertyChanged();
                }
            }
        }
        private String _text = String.Empty;

        public DemoViewModel()
        {
            Text = "Bla";
        }

        public void OnPropertyChanged([CallerMemberName] string name = "") =>
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));

    }

}

grafik

This issue was supposed to be fixed in #9418, it is easily reproducible that it was not though. See reproduction project below (use entry-crash-branch)

Steps to Reproduce

  1. Create a blank MAUI project
  2. Add an Entry element like this one: <Entry Text="{Binding Text}" MaxLength="2"/>
  3. Set the Text binding to a String with a length > 2 characters in the according ViewModel
  4. Run on Android
  5. App crashes 💥

Link to public reproduction project repository

https://github.com/Delphin-Technology/maui-issue-samples/tree/entry-crash

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Delphinidae84 avatar Jan 04 '24 11:01 Delphinidae84

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Jan 16 '24 08:01 ghost

The issue will be fixed by https://github.com/dotnet/maui/tree/fix-19689

jsuarezruiz avatar Jan 16 '24 09:01 jsuarezruiz

When will this be merged into a release? I am in dire need of this but it was not in the last release on Feb. 14.

SchallerStefan avatar Mar 12 '24 13:03 SchallerStefan

When will this be merged into a release? I am in dire need of this but it was not in the last release on Feb. 14.

Same, @jsuarezruiz is there a reason, why your fix didn't make it into the last release?

Delphinidae84 avatar Mar 12 '24 13:03 Delphinidae84

@jsuarezruiz @PureWeen is there a timeline for prioritizing this? Watching the streams for hope!

shawncothran avatar May 07 '24 15:05 shawncothran

/similarissues

samhouts avatar May 23 '24 23:05 samhouts

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar May 23 '24 23:05 github-actions[bot]

I've been seeing the same symptom in Android Play Store testing of my App so I don't think it is only caused by code behind sending too long a value. Unfortunately, I cannot reproduce it so far, but I suspect it's caused by Play Store random input testing. The problem went away when I eliminated the MaxLength value from the half dozen or so entry fields that used it, so that's pretty good circumstantial evidence that it's a related issue.

david-maw avatar Jun 27 '24 17:06 david-maw

Is there any chance that fix will be included in next release? According to @jsuarezruiz It has been fixed on Jan 16 2024...

Sztub avatar Jul 22 '24 12:07 Sztub