Skip to content

RNTester Andriod crash when opening: Error while updating prop color #24288

Closed
@maxiee

Description

🐛 Bug Report

I pull the latest code from the master branch and successfully compiled the Android APP and started the packager.

When I open the RNTester APP from the device, RNTester crashed when executing the bundle code with following error:

2019-04-03 18:15:30.266 11130-11234/com.facebook.react.uiapp E/unknown:ViewManager: Error while updating prop color
    java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
        at com.facebook.react.uimanager.ViewManagersPropertyCache$BoxedIntPropSetter.getValueOrDefault(ViewManagersPropertyCache.java:291)
        at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateShadowNodeProp(ViewManagersPropertyCache.java:106)
        at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackShadowNodeSetter.setProperty(ViewManagerPropertyUpdater.java:156)
        at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:60)
        at com.facebook.react.uimanager.ReactShadowNodeImpl.updateProperties(ReactShadowNodeImpl.java:319)
        at com.facebook.react.uimanager.UIImplementation.createView(UIImplementation.java:266)
        at com.facebook.react.uimanager.UIManagerModule.createView(UIManagerModule.java:464)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:101)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:166)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:784)
2019-04-03 18:15:30.280 11130-11234/com.facebook.react.uiapp E/unknown:ReactNative: Exception in native call
    com.facebook.react.bridge.JSApplicationIllegalArgumentException: Error while updating property 'color' in shadow node of type: RCTText
        at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateShadowNodeProp(ViewManagersPropertyCache.java:121)
        at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackShadowNodeSetter.setProperty(ViewManagerPropertyUpdater.java:156)
        at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:60)
        at com.facebook.react.uimanager.ReactShadowNodeImpl.updateProperties(ReactShadowNodeImpl.java:319)
        at com.facebook.react.uimanager.UIImplementation.createView(UIImplementation.java:266)
        at com.facebook.react.uimanager.UIManagerModule.createView(UIManagerModule.java:464)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:101)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:166)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:784)
     Caused by: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
        at com.facebook.react.uimanager.ViewManagersPropertyCache$BoxedIntPropSetter.getValueOrDefault(ViewManagersPropertyCache.java:291)

To Reproduce

  1. pull the lastet code from master (current the latest is d9711e2)
  2. Install RNTester APP to device
  3. start packager
  4. open RNTester app
  5. RNTester crashed

Expected Behavior

RNTester will crash when open

Code Example

I have a look into the crash log, and found the error is related to com.facebook.react.uimanager.ViewManagersPropertyCache.BoxedIntPropSetter#getValueOrDefault, which is as following:

protected @Nullable Object getValueOrDefault(Object value) {
  if (value != null) {
    return (Integer) value;
  }
  return null;
}

The crash log says the value param has type of Double, which cannot be cast to Integer.

I try to fix this bug with a dirty fix:

protected @Nullable Object getValueOrDefault(Object value) {
  if (value != null) {
    if (value instanceof Double) {
      return  ((Double) value).intValue();
    } else {
      return  (Integer) value;
    }
  }
  return null;
}

With the fix above, RNTester will run successfully. But I'm not sure if the fix is appropriate.

Environment

React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 1.20 GB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.8.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
Watchman: 4.7.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 19, 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 19.1.0, 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.2, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.2, 28.0.3
System Images: android-23 | Android TV ARM EABI v7a, android-23 | Android TV Intel x86 Atom, android-23 | Android Wear ARM EABI v7a, android-23 | Google APIs ARM EABI v7a, android-23 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5314842
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: master
react-native: master

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions