react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Removing textDecorationLine style from a TextInput causes Android NPE crash

Open tibbe opened this issue 2 years ago • 3 comments

Description

If you have a TextInput with a textDecorationLine style set and then remove the style we get the following Android crash:

Caused by java.lang.NullPointerException
Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference

com.facebook.react.views.textinput.ReactTextInputManager.setTextDecorationLine (Unknown Source:11)
java.lang.reflect.Method.invoke (Method.java)
com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp (ViewManagersPropertyCache.java:54)
com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter.setProperty (ViewManagerPropertyUpdater.java:10)
com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps (ViewManagerPropertyUpdater.java:36)
com.facebook.react.uimanager.ViewManager.updateProperties (Unknown Source:10)
com.facebook.react.uimanager.NativeViewHierarchyManager.updateProperties (NativeViewHierarchyManager.java:14)
com.facebook.react.uimanager.UIViewOperationQueue$UpdatePropertiesOperation.execute (UIViewOperationQueue.java:10)
com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:135)
com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:53)
com.facebook.react.uimanager.UIViewOperationQueue.access$2600 (UIViewOperationQueue.java)
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded (UIViewOperationQueue.java:31)
com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java)
com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame (ReactChoreographer.java:46)
com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame (ChoreographerCompat.java:2)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1158)
android.view.Choreographer.doCallbacks (Choreographer.java:950)
android.view.Choreographer.doFrame (Choreographer.java:874)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1142)
android.os.Handler.handleCallback (Handler.java:938)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loopOnce (Looper.java:210)
android.os.Looper.loop (Looper.java:299)
android.app.ActivityThread.main (ActivityThread.java:8319)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:556)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1038)

The cause can easily be seen in the Android code: https://github.com/facebook/react-native/blob/8c779cd630830149c4d33d386ccd3a9a84517d37/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java#L947

We have a @Nullable field but use it without checking if it's null.


React Native Version

0.71.13

Output of npx react-native info

System:
    OS: macOS 13.5.2
    CPU: (8) arm64 Apple M1 Pro
    Memory: 282.09 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    Yarn: Not Found
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
    Watchman: 2023.07.03.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/tibbe/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.10121639
    Xcode: 15.0/15A240d - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.19 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.13 => 0.71.13 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

Have a TextInput with above style set. Remove it programatically (e.g. when the user clicks a button).

Snack, screenshot, or link to a repository

https://snack.expo.dev/FTtlEKOrI

tibbe avatar Sep 26 '23 14:09 tibbe

The Text component code handles this correctly so perhaps a fix could be taken from there: https://github.com/facebook/react-native/blob/8c779cd630830149c4d33d386ccd3a9a84517d37/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java#L543

tibbe avatar Sep 26 '23 14:09 tibbe

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Apr 03 '24 05:04 github-actions[bot]

Still an issue.

tibbe avatar Apr 03 '24 06:04 tibbe