Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14081] Android: app crashes when trying to paste more than maxLength characters in text field

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2013-06-03T18:56:33.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 12 API, 2013 Sprint 12, Release 3.2.0
ComponentsAndroid
LabelsSupportTeam
ReporterDavide Cassenti
AssigneeIngo Muschenetz
Created2013-06-01T06:25:44.000+0000
Updated2017-03-23T18:25:35.000+0000

Description

Problem description

When trying to paste a string that is larger than the maximum allowed for a text field (e.g. greater than maxLength), the app crashes.

Steps to reproduce

USe the following code. The text field has a max length of 10 characters. Copy a string of at least 11 (e.g. '12345678910') and paste into it. The app will immediatly crash. Works fine in native Android.

Error Log

06-01 07:19:59.548: E/TiApplication(18418): (main) [12162,12162] Sending event: exception on thread: main msg:java.lang.IndexOutOfBoundsException: setSpan (10 ... 10) ends beyond length 0; Titanium 3.1.0,2013/04/15 18:46,57634ef 06-01 07:19:59.548: E/TiApplication(18418): java.lang.IndexOutOfBoundsException: setSpan (10 ... 10) ends beyond length 0 06-01 07:19:59.548: E/TiApplication(18418): at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1016) 06-01 07:19:59.548: E/TiApplication(18418): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:592) 06-01 07:19:59.548: E/TiApplication(18418): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588) 06-01 07:19:59.548: E/TiApplication(18418): at android.text.Selection.setSelection(Selection.java:76) 06-01 07:19:59.548: E/TiApplication(18418): at android.text.Selection.setSelection(Selection.java:87) 06-01 07:19:59.548: E/TiApplication(18418): at android.widget.EditText.setSelection(EditText.java:94) 06-01 07:19:59.548: E/TiApplication(18418): at ti.modules.titanium.ui.widget.TiUIText.onTextChanged(TiUIText.java:285) 06-01 07:19:59.548: E/TiApplication(18418): at android.widget.TextView.sendOnTextChanged(TextView.java:7231) 06-01 07:19:59.548: E/TiApplication(18418): at android.widget.TextView.handleTextChanged(TextView.java:7290) 06-01 07:19:59.548: E/TiApplication(18418): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:8880) 06-01 07:19:59.548: E/TiApplication(18418): at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:962) 06-01 07:19:59.548: E/TiApplication(18418): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:496) 06-01 07:19:59.548: E/TiApplication(18418): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:435) 06-01 07:19:59.548: E/TiApplication(18418): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:30) 06-01 07:19:59.548: E/TiApplication(18418): at android.widget.TextView.paste(TextView.java:8275) 06-01 07:19:59.548: E/TiApplication(18418): at android.widget.TextView.onTextContextMenuItem(TextView.java:8036) 06-01 07:19:59.548: E/TiApplication(18418): at android.widget.Editor$ActionPopupWindow.onClick(Editor.java:2862) 06-01 07:19:59.548: E/TiApplication(18418): at android.view.View.performClick(View.java:4204) 06-01 07:19:59.548: E/TiApplication(18418): at android.view.View$PerformClick.run(View.java:17355) 06-01 07:19:59.548: E/TiApplication(18418): at android.os.Handler.handleCallback(Handler.java:725) 06-01 07:19:59.548: E/TiApplication(18418): at android.os.Handler.dispatchMessage(Handler.java:92) 06-01 07:19:59.548: E/TiApplication(18418): at android.os.Looper.loop(Looper.java:137) 06-01 07:19:59.548: E/TiApplication(18418): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-01 07:19:59.548: E/TiApplication(18418): at java.lang.reflect.Method.invokeNative(Native Method) 06-01 07:19:59.548: E/TiApplication(18418): at java.lang.reflect.Method.invoke(Method.java:511) 06-01 07:19:59.548: E/TiApplication(18418): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-01 07:19:59.548: E/TiApplication(18418): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-01 07:19:59.548: E/TiApplication(18418): at dalvik.system.NativeStart.main(Native Method) 06-01 07:19:59.588: E/AndroidRuntime(18418): FATAL EXCEPTION: main 06-01 07:19:59.588: E/AndroidRuntime(18418): java.lang.IndexOutOfBoundsException: setSpan (10 ... 10) ends beyond length 0 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1016) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:592) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.Selection.setSelection(Selection.java:76) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.Selection.setSelection(Selection.java:87) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.widget.EditText.setSelection(EditText.java:94) 06-01 07:19:59.588: E/AndroidRuntime(18418): at ti.modules.titanium.ui.widget.TiUIText.onTextChanged(TiUIText.java:285) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.widget.TextView.sendOnTextChanged(TextView.java:7231) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.widget.TextView.handleTextChanged(TextView.java:7290) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:8880) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:962) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:496) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:435) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:30) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.widget.TextView.paste(TextView.java:8275) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.widget.TextView.onTextContextMenuItem(TextView.java:8036) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.widget.Editor$ActionPopupWindow.onClick(Editor.java:2862) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.view.View.performClick(View.java:4204) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.view.View$PerformClick.run(View.java:17355) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.os.Handler.handleCallback(Handler.java:725) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.os.Handler.dispatchMessage(Handler.java:92) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.os.Looper.loop(Looper.java:137) 06-01 07:19:59.588: E/AndroidRuntime(18418): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-01 07:19:59.588: E/AndroidRuntime(18418): at java.lang.reflect.Method.invokeNative(Native Method) 06-01 07:19:59.588: E/AndroidRuntime(18418): at java.lang.reflect.Method.invoke(Method.java:511) 06-01 07:19:59.588: E/AndroidRuntime(18418): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-01 07:19:59.588: E/AndroidRuntime(18418): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-01 07:19:59.588: E/AndroidRuntime(18418): at dalvik.system.NativeStart.main(Native Method)

Comments

  1. Ping Wang 2013-06-03

    Should already be fixed in 3.1.1. The fix is in [PR#4072](https://github.com/appcelerator/titanium_mobile/pull/4072) and [PR#4193](https://github.com/appcelerator/titanium_mobile/pull/4193) for TIMOB-12139.
  2. Lee Morris 2017-03-23

    Closing ticket as duplicate with reference to the linked issues above.

JSON Source