react-native: TextInput secureTextEntry crashing on Android custom keyboard?

Is this a bug report?

Yes.

Have you read the Contributing Guidelines?

Yes.

Environment

Environment: OS: macOS High Sierra 10.13.3 Node: 9.4.0 Yarn: 1.0.2 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed) react: ^16.2.0 => 16.2.0 react-native: 0.53.0 => 0.53.0

Tested on Devices:

  • Plus One Japan Limited FTJ161B (Android 6.0, API 23)
  • Samsung Galaxy Note 8 (Android 7.1.1)

Steps to Reproduce

Using com.justsystems.atokmobile.tv.service custom keyboard then typing into a <TextInput secureTextEntry={true}> field yields the following crash:

13:16:19.098 4410-4410/com.example.dev E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.dev, PID: 4410 java.lang.IndexOutOfBoundsException: charAt: -1 < 0 at android.text.SpannableStringBuilder.charAt(SpannableStringBuilder.java:122) at com.facebook.react.views.textinput.ReactEditTextInputConnectionWrapper.setComposingText(ReactEditTextInputConnectionWrapper.java:104) at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:340) at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5728) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

  1. Focus the <TextInput>
  2. On the soft keyboard, hitting the “1” key and the “backspace” key in alternation seems to cause the crash although it seems random.

Issue isn’t present with the Google AOSP keyboard. Seems to happen only with this keyboard and the secureTextEntry={true}.

Expected Behavior

This should work on all keyboards.

Actual Behavior

feb-09-2018 13-50-14

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

(As your stack trace suggests), specifically the problem is to do with this line: https://github.com/facebook/react-native/blob/0.53-stable/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java#L104. At the very least, this should be guarded against. I’m looking into why there seems to be a race condition. Will post updates.

@apparition47 thank you for checking this out and providing a detailed issue! I haven’t managed to reproduce this issue yet (on a simulator) but will try on a device as soon as I can.

So I don’t know much about the point release process, but I think this fix should be eligible to be merged into 0.53 (as well as master). I’ll work on getting this done

Thanks @joshyhargreaves. It would be nice if there was bug fix releases in RN though, because while this bug will be fixed in 0.54, I expect there will be new ones too, which means upgrade is never possible. I’m still at 0.49 because 0.51 had a crash in iOS, and 0.53 this crash in Android.

I have addressed the crash in https://github.com/facebook/react-native/commit/b60a727adbcfa785e3d1b13bf069b766216e60f8 which is now in master. I will close this Issue and leave https://github.com/facebook/react-native/issues/17974 open until we know if the commit will make into the 0.54 release.