Bug 26451 - [Android] Length validation in Entry.TextChanged event throws exception
Summary: [Android] Length validation in Entry.TextChanged event throws exception
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.1
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Chris King
URL:
Depends on:
Blocks:
 
Reported: 2015-01-27 05:57 UTC by Prashant Cholachagudda
Modified: 2015-06-23 18:31 UTC (History)
6 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:


Attachments
testcase (2.24 MB, application/zip)
2015-01-27 05:57 UTC, Prashant Cholachagudda
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Prashant Cholachagudda 2015-01-27 05:57:19 UTC
Created attachment 9515 [details]
testcase

The following code crashes the app when using Keyboard.Default or Keyboard.Text in Android. All other keyboards work fine.

public class TestPage : ContentPage
{
            public TestPage()
            {
                        Entry entry = new Entry { Keyboard = Keyboard.Text };
                        entry.TextChanged += entry_TextChanged;
                        Content = entry;
            }
 
            void entry_TextChanged(object sender, TextChangedEventArgs e)
            {
                        if ((e.NewTextValue ?? "").Length > 5)
                        {
                                    ((Entry) sender).Text = e.OldTextValue; // Crashes app.
                        }
            }
}


Stacktrace: 
E/AndroidRuntime(  567): java.lang.IndexOutOfBoundsException: setSpan (5 ... 6) ends beyond length 5
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:945)
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:527)
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:520)
E/AndroidRuntime(  567): 	at android.widget.SpellChecker$SpellParser.init(SpellChecker.java:403)
E/AndroidRuntime(  567): 	at android.widget.SpellChecker.spellCheck(SpellChecker.java:224)
E/AndroidRuntime(  567): 	at android.widget.TextView.updateSpellCheckSpans(TextView.java:7810)
E/AndroidRuntime(  567): 	at android.widget.TextView.sendOnTextChanged(TextView.java:7638)
E/AndroidRuntime(  567): 	at android.widget.TextView.handleTextChanged(TextView.java:7681)
E/AndroidRuntime(  567): 	at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:8044)
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:892)
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:352)
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:266)
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:443)
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:420)
E/AndroidRuntime(  567): 	at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:29)
E/AndroidRuntime(  567): 	at android.text.method.QwertyKeyListener.onKeyDown(QwertyKeyListener.java:218)
E/AndroidRuntime(  567): 	at android.text.method.TextKeyListener.onKeyDown(TextKeyListener.java:132)
E/AndroidRuntime(  567): 	at android.widget.TextView.doKeyDown(TextView.java:5445)
E/AndroidRuntime(  567): 	at android.widget.TextView.onKeyDown(TextView.java:5267)
E/AndroidRuntime(  567): 	at android.view.KeyEvent.dispatch(KeyEvent.java:2551)
E/AndroidRuntime(  567): 	at android.view.View.dispatchKeyEvent(View.java:5500)
E/AndroidRuntime(  567): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
E/AndroidRuntime(  567): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
E/AndroidRuntime(  567): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
E/AndroidRuntime(  567): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
E/AndroidRuntime(  567): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
E/AndroidRuntime(  567): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
E/AndroidRuntime(  567): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
E/AndroidRuntime(  567): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
E/AndroidRuntime(  567): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1879)
E/AndroidRuntime(  567): 	at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1361)
E/AndroidRuntime(  567): 	at android.app.Activity.dispatchKeyEvent(Activity.java:2324)
E/AndroidRuntime(  567): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1806)
E/AndroidRuntime(  567): 	at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3327)
E/AndroidRuntime(  567): 	at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3300)
E/AndroidRuntime(  567): 	at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2460)
E/AndroidRuntime(  567): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  567): 	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(  567): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(  567): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  567): 	at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(  567): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(  567): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(  567): 	at dalvik.system.NativeStart.main(Native Method)
Comment 2 Jason Smith [MSFT] 2015-05-29 21:19:10 UTC
You should consider adding a small delay or using a coercion filter with your a binding until we can work around the issue in Android. It doesn't like the value being changed immediately after the keypress.
Comment 3 Chris King 2015-06-23 18:31:04 UTC
Appears to be fixed on the latest dev branch. Let us know if you still see it.

Warm regards,
XFT