maui
maui copied to clipboard
Java.Lang.IndexOutOfBoundsException: 'setSpan ( ... ) ends beyond length
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));
}
}
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
- Create a blank MAUI project
- Add an Entry element like this one:
<Entry Text="{Binding Text}" MaxLength="2"/> - Set the
Textbinding to aStringwith a length > 2 characters in the according ViewModel - Run on Android
- 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
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.
The issue will be fixed by https://github.com/dotnet/maui/tree/fix-19689
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.
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?
@jsuarezruiz @PureWeen is there a timeline for prioritizing this? Watching the streams for hope!
/similarissues
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:
- Java.Lang.IndexOutOfBoundsException: setSpan (12 ... 12) ends beyond length 10 (#21944), similarity score: 0.79
Closed similar issues:
- Java.Lang.IndexOutOfBoundsException: 'setSpan ( ... ) ends beyond length (#9418), similarity score: 0.87
- Binding of Entry control seems to break after entering text in Entry (#16859), similarity score: 0.72
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
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.
Is there any chance that fix will be included in next release? According to @jsuarezruiz It has been fixed on Jan 16 2024...