React-native-reanimated: [Android] NullPointerException - java.util.ArrayDeque.addLast from com.swmansion.reanimated.NodesManager.startUpdatingOnAnimationFrame

Created on 11 Feb 2020  路  10Comments  路  Source: software-mansion/react-native-reanimated

Hi there,

We started seeing this error when we upgraded another library which in turn required an upgrade to Reanimated from 1.0.0 to 1.4.0:

java.lang.NullPointerException
    ArrayDeque.java:228 java.util.ArrayDeque.addLast
    ReactChoreographer:91 com.facebook.react.modules.core.ReactChoreographer.postFrameCallback
    NodesManager:130 com.swmansion.reanimated.NodesManager.startUpdatingOnAnimationFrame
    NodesManager:382 com.swmansion.reanimated.NodesManager.onEventDispatch
    EventDispatcher:113 com.facebook.react.uimanager.events.EventDispatcher.dispatchEvent
    UIImplementation:919 com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive
...
    UIImplementation:904 com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive
    UIImplementation:644 com.facebook.react.uimanager.UIImplementation.updateViewHierarchy
    UIImplementation:599 com.facebook.react.uimanager.UIImplementation.dispatchViewUpdates
    UIManagerModule:782 com.facebook.react.uimanager.UIManagerModule.onBatchComplete
    NativeModuleRegistry:118 com.facebook.react.bridge.NativeModuleRegistry.onBatchComplete
    CatalystInstanceImpl:164 com.facebook.react.bridge.CatalystInstanceImpl$BridgeCallback.onBatchComplete
    SourceFile:-2 com.facebook.react.bridge.queue.NativeRunnable.run
    Handler.java:789 android.os.Handler.handleCallback
    Handler.java:98 android.os.Handler.dispatchMessage
    MessageQueueThreadHandler:26 com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage
    Looper.java:164 android.os.Looper.loop
    MessageQueueThreadImpl:225 com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run
    Thread.java:764 java.lang.Thread.run

This implies that NodesManager's mChoreographerCallback is null, which doesn't make sense since it gets initialized in the constructor.

Since other issues have mentioned that 1.7.0 has fixes for other NPEs, we tried upgrading to 1.7.0, but that hasn't helped. I'm still investigating, but am wondering if others have seen this problem or know a workaround?

Thanks!

馃悶 Bug 馃android 馃Оneed-repro

Most helpful comment

We've temporarily used patch-package to cover it up in node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java

   private void startUpdatingOnAnimationFrame() {
     if (!mCallbackPosted.getAndSet(true)) {
-      mReactChoreographer.postFrameCallback(
-              ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE,
-              mChoreographerCallback);
+      // attempt to suppress NPE spike described in: 
+      // https://github.com/software-mansion/react-native-reanimated/issues/604
+      if (mChoreographerCallback != null) {
+        mReactChoreographer.postFrameCallback(
+                ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE,
+                mChoreographerCallback);
+      }
     }
   }

This 'fixed it' and surprisingly the crash didn't move elsewhere.

All 10 comments

Can confirm we're running into the same error on android versions 5-10, running [email protected] and [email protected]

Fatal Exception: java.lang.NullPointerException
       at java.util.ArrayDeque.addLast(ArrayDeque.java:228)
       at com.facebook.react.modules.core.ReactChoreographer.postFrameCallback(ReactChoreographer.java:91)
       at com.swmansion.reanimated.NodesManager.startUpdatingOnAnimationFrame(NodesManager.java:130)
       at com.swmansion.reanimated.NodesManager.onEventDispatch(NodesManager.java:382)
       at com.facebook.react.uimanager.events.EventDispatcher.dispatchEvent(EventDispatcher.java:113)
       at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:919)
       at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:904)
       at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:904)
       at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:904)
       at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:904)
       at com.facebook.react.uimanager.UIImplementation.updateViewHierarchy(UIImplementation.java:644)
       at com.facebook.react.uimanager.UIImplementation.dispatchViewUpdates(UIImplementation.java:599)
       at com.facebook.react.uimanager.UIManagerModule.onBatchComplete(UIManagerModule.java:782)
       at com.facebook.react.bridge.NativeModuleRegistry.onBatchComplete(NativeModuleRegistry.java:118)
       at com.facebook.react.bridge.CatalystInstanceImpl$BridgeCallback.onBatchComplete(CatalystInstanceImpl.java:164)
       at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
       at android.os.Looper.loop(Looper.java:193)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
       at java.lang.Thread.run(Thread.java:764)

Hi @jlimz and @Caundy,

I investigated this error a bit, it crashes at mCallbackQueues[type.getOrder()].addLast(frameCallback);

NPE here triggers:

  • mChoreographerCallback being null and the only situation this can be null is when something explicitly sets it to null, because as @jlimz noticed it get set in c-tor.
  • or mCallbackQueues[type.getOrder()] being null and after checking I don't see why it could be null
    I don't know really why it happens, I'd really appreciate some form of reproduction example.

@Caundy - I'm wondering if there is any overlap between our two projects for some of the libraries that rely on reanimated. Maybe commonality will provide a clue.

Here's a snapshot of a few libraries we are using that could be relevant:

"react-native-gesture-handler": "1.5.1",
"react-native-reanimated": "1.7.0",
"react-native-tab-view": "2.11.0",
"react-native-tab-view-viewpager-adapter": "1.0.7",
"react-navigation": "4.0.10",
"react-navigation-stack": "1.10.3",
"react-navigation-tabs": "2.7.0",

Same here

    "react-native": "0.61.5",
    "react-native-animatable": "^1.3.3",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-linear-gradient": "^2.4.3",
    "react-native-reanimated": "^1.3.0",
    "react-native-tab-view": "^2.10.0",
    "react-navigation": "3.13.0",

We've temporarily used patch-package to cover it up in node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java

   private void startUpdatingOnAnimationFrame() {
     if (!mCallbackPosted.getAndSet(true)) {
-      mReactChoreographer.postFrameCallback(
-              ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE,
-              mChoreographerCallback);
+      // attempt to suppress NPE spike described in: 
+      // https://github.com/software-mansion/react-native-reanimated/issues/604
+      if (mChoreographerCallback != null) {
+        mReactChoreographer.postFrameCallback(
+                ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE,
+                mChoreographerCallback);
+      }
     }
   }

This 'fixed it' and surprisingly the crash didn't move elsewhere.

I've also seen this in my crash logs and it so far has only affected Android 5 and 6
I'm using 1.8.0

Still seeing the same crashes on Android 7-10 using react-native-reanimated 1.9.0 & react-navigation 5.x

We need some repro to debug it, having stacktraces helps a bit, but I'd like to check out it locally.

@jakub-gonet that makes total sense. Unfortunately, the error is only seen in production and can't be reproduced locally yet. That said, it seems to crash fairly early on (within the first 1-3s post launch), which makes me suspect it might related to the timing of initialization.

Thanks @smacgregor .

For for react-native-reanimated v1.9.0

The file to patch is node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sa8ab picture sa8ab  路  3Comments

bjartebore picture bjartebore  路  3Comments

colinux picture colinux  路  3Comments

zxccvvv picture zxccvvv  路  3Comments

robertgonzales picture robertgonzales  路  3Comments