react-native: IndexOutOfBoundsException when using Google Indic Keyboard with RN 0.53.0

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: macOS High Sierra 10.13.2 Node: 8.4.0 Yarn: 0.27.5 npm: 5.3.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

Target Platform: Android (6.0.1)

Steps to Reproduce

  1. Create and run a new project with RN 0.53.0, using react-native init. (Most likely exists for projects created using other methods as well, didn’t check.)
  2. Switch the keyboard to Google Indic Keyboard from phone’s input settings
  3. Steps for reproducing the crash with emojis: a. Create a TextInput with no additional props (or switch to the master branch of the provided repo). a. Type an emoji and press the backspace twice.
  4. Steps for reproducing the crash with any character: a. Create a TextInput with autoCorrect={false} (or switch to the auto-correct branch of the provided repo). a. Type any character and press the backspace once.

Expected Behavior

The emojis and characters get cleared with no crashes

Actual Behavior

screenshot_2018-02-14-10-04-04-422_com android settings

The app crashes on clearing the emojis, with no additional props set on the TextInput 2018-02-14 10_37_49 The app crashes on clearing the last character in case autoCorrect={false} is set 2018-02-14 10_38_17

Reproducible Demo

https://github.com/SuhairZain/react-native-gindic-keyboard-crash The master branch crashes when deleting an emoji character The auto-correct branch crashes when deleting the last character in the input

The reason that I’ve created this issue here rather than on the Google Indic keyboard repo is that I can confirm that this bug does not exist with 0.47.1, which is the version our app was on before we upgraded. This is a bug that was introduced in one of the versions from then to 0.53.0.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 39 (29 by maintainers)

Commits related to this issue

Most upvoted comments

@joshyhargreaves Thanks! I built an APK with it and sent it over to my team.

@ccdwyer no problem, I will do this evening as currently AFK!

I’lll re-open until we know if this commit make it into the 0.54 release.

@kelset I’ll put in a PR to master in a few hours. Hopefully @kmagiera won’t mind giving it a review!

Hey @kelset, thank you for the crash reports, I had actually suspected that their might be a few different ways that this bug could manifest itself. One of the main issues I’ve had actually, is I haven’t been able to repro it myself actually, but I will put in some more effort. I’m entirely sure, that the fix I posted wouldn’t result in any more indexOutOfBoundsExceptions.

Looking at your stack traces, I’m not actually that confident that that the fix I posted previously would fix these, as it seems like the reference to the wrapped InputConnection can turn null, but I will do a bit of thinking/researching over the next few hours.

I will absolutely put in a pull request for this, I think it may be a good idea also to only enable this codepath if using ‘onKeyPress’, and so I will have a look at that also!

Let’s just get this fixed, thanks again for the crash reports.

👋 @joshyhargreaves

I think that the issue OP posted is actually just one of the ways the bug can manifest itself (and #17922 is another) - this weekend we released the latest update to our app with RN 0.53 and I have 3 different crash reports that seems to be all related to the same root issue:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'android.os.Handler android.view.inputmethod.InputConnection.getHandler()' on a null object reference
       at android.view.inputmethod.InputConnectionWrapper.getHandler(InputConnectionWrapper.java:262)
       at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1703)
       at android.view.inputmethod.InputMethodManager$H.handleMessage(InputMethodManager.java:558)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6692)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'android.view.inputmethod.ExtractedText android.view.inputmethod.InputConnection.getExtractedText(android.view.inputmethod.ExtractedTextRequest, int)' on a null object reference
       at android.view.inputmethod.InputConnectionWrapper.getExtractedText(InputConnectionWrapper.java:62)
       at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:273)
       at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:5523)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.finishComposingText()' on a null object reference
       at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
       at android.view.inputmethod.InputMethodManager.checkFocusNoStartInput(InputMethodManager.java:1543)
       at android.view.inputmethod.InputMethodManager.onWindowFocus(InputMethodManager.java:1587)
       at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3958)
       at android.os.Handler.dispatchMessage(Handler.java:111)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:6102)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

Sadly I can’t post much more of the stacktrace since it comes from the minified prod version; but I strongly believe the fix you linked earlier will solve these crashes too (I can’t dive deeper into creating a repro or doing a new release pointing at your branch because of higher prior tasks this week).

It’s still quite a small ‘surface’, since we are talking about a precise set of actions on a custom keyboard on Android (overall, we got less than 20 crashes reported by up to 6 users - which is a .00x% of our userbase) so no rush, but are you planning on doing a PR with it?

I don’t think, since it’s already late Feb, that it would be merged & cherry picked into a new 0.53.x release, but I think it would be possible to have it in 0.54 💪

(ps: ofc if there’s anything that I can do to help let me know!)

@joshyhargreaves It appears that the crash is gone for us with your change. Thanks!