react-native: ReactSlider crash on Android release version

Issue Description

Hard crash randomly and unexpectedly on Android release version only (debug is fine, iOS is fine on both debug and release) when hiding and displaying sliders based on a state variable.

Steps to Reproduce / Code Snippets

We have a number of photo filters in our app which are selected by <TouchableOpacity> components and some have a slider to adjust the blur or brightness etc. These sliders are completely separate from each other and are displayed based on a string stored in the components state called filter.

Here is one such slider from render():

{filter === 'gamify' && ( <View style={styles.filterSlider}> <Text>How retro do you want to go?</Text> <Slider value={this.state.pixelSize} minimumValue={1} maximumValue={5} onValueChange={value => this.setState({pixelSize: value})} /> </View>)}

Expected Results

No crash when hiding and displaying sliders

Stack Trace

java.lang.NullPointerException: Attempt to write to field ‘java.util.ArrayList android.animation.AnimatorSet$Node.nodeDependents’ on a null object reference

http://pastebin.com/270Wg6Pu

Additional Information

  • React Native version: 0.33
  • Platform(s) (iOS, Android, or both?): Android (Release only)
  • Operating System (macOS, Linux, or Windows?): Mac OSX

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 23
  • Comments: 45 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

why closed? this crash is still not fix

Android 7.0 in production HUAWEI (VNS-L31) ReactNative 0.58

Caused by: java.lang.NullPointerException Attempt to read from field ‘android.animation.Animator android.animation.AnimatorSet$Node.mAnimation’ on a null object reference

AnimatorSet.java:725 android.animation.AnimatorSet.clone

AnimatorSet.java:682 android.animation.AnimatorSet.clone

Animator.java:589 android.animation.Animator$AnimatorConstantState.newInstance

Animator.java:588 android.animation.Animator$AnimatorConstantState.newInstance

ConstantState.java:52 android.content.res.ConstantState.newInstance

ConstantState.java:60 android.content.res.ConstantState.newInstance

ConfigurationBoundResourceCache.java:40 android.content.res.ConfigurationBoundResourceCache.getInstance

AnimatorInflater.java:116 android.animation.AnimatorInflater.loadAnimator

AnimatedVectorDrawable.java:666 android.graphics.drawable.AnimatedVectorDrawable$AnimatedVectorDrawableState$PendingAnimator.newInstance

AnimatedVectorDrawable.java:644 android.graphics.drawable.AnimatedVectorDrawable$AnimatedVectorDrawableState.inflatePendingAnimators

AnimatedVectorDrawable.java:454 android.graphics.drawable.AnimatedVectorDrawable.applyTheme

DrawableContainer.java:960 android.graphics.drawable.DrawableContainer$DrawableContainerState.applyTheme

DrawableContainer.java:611 android.graphics.drawable.DrawableContainer.applyTheme

StateListDrawable.java:371 android.graphics.drawable.StateListDrawable.applyTheme

AnimatedStateListDrawable.java:392 android.graphics.drawable.AnimatedStateListDrawable.applyTheme

ResourcesImpl.java:778 android.content.res.ResourcesImpl.loadDrawable

Resources.java:921 android.content.res.Resources.loadDrawable

TypedArray.java:983 android.content.res.TypedArray.getDrawable

AbsSeekBar.java:110 android.widget.AbsSeekBar.<init>

SeekBar.java:85 android.widget.SeekBar.<init>

SeekBar.java:81 android.widget.SeekBar.<init>

AppCompatSeekBar.java:47 android.support.v7.widget.AppCompatSeekBar.<init>

ReactSlider.java:51 com.facebook.react.views.slider.ReactSlider.<init>

ReactSliderManager.java:66 com.facebook.react.views.slider.ReactSliderManager$ReactSliderShadowNode.measure

YogaNode.java:740 com.facebook.yoga.YogaNode.measure

YogaNode.java:-2 com.facebook.yoga.YogaNode.jni_YGNodeCalculateLayout

YogaNode.java:280 com.facebook.yoga.YogaNode.calculateLayout

ReactShadowNodeImpl.java:421 com.facebook.react.uimanager.ReactShadowNodeImpl.calculateLayout

UIImplementation.java:968 com.facebook.react.uimanager.UIImplementation.calculateRootLayout

UIImplementation.java:710 com.facebook.react.uimanager.UIImplementation.updateViewHierarchy

UIImplementation.java:670 com.facebook.react.uimanager.UIImplementation.dispatchViewUpdates

UIManagerModule.java:761 com.facebook.react.uimanager.UIManagerModule.onBatchComplete

NativeModuleRegistry.java:118 com.facebook.react.bridge.NativeModuleRegistry.onBatchComplete

CatalystInstanceImpl.java:155 com.facebook.react.bridge.CatalystInstanceImpl$BridgeCallback.onBatchComplete

NativeRunnable.java:-2 com.facebook.react.bridge.queue.NativeRunnable.run

Handler.java:761 android.os.Handler.handleCallback

Handler.java:98 android.os.Handler.dispatchMessage

MessageQueueThreadHandler.java:29 com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage

Looper.java:156 android.os.Looper.loop

MessageQueueThreadImpl.java:232 com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run

Thread.java:776 java.lang.Thread.run

@ShaMan123 You can try one of the workarounds I provided. It seems like there is a workaround being provided by the React Native team as well, but you might want to wait for a stable release. We used https://github.com/jeanregisser/react-native-slider as a alternative.

Can confirm that I’m still seeing this issue RN 0.52

I’ve been getting the same crash in AnimatorSet with a button created in a custom Android ViewManager, since at least 0.33. The crash is very rare relative to the number of times the view manager in question creates buttons, and happens in both release and debug on Android only.

The line in question is:

Button button = new Button(context);

(There is also an identical line in the shadow node which causes identical issues)

I can pretty much guarantee the crash occurring by wrapping the line above in a loop. I didn’t look into it deeply, but the nature of the problem and analysis of the code in AnimatorSet suggested it might be a threading issue. Sure enough, wrapping the line of code above in a block synchronized on something available to both the ViewManager and ShadowNode (e.g. the React context) eradicates the issue, although I assume the crash will still happen if code I don’t have control over also creates / inflates Buttons concurrently with mine. The line has to be synchronized in both the ViewManager and the ShadowNode.

Hopefully that narrows down the issue with the Slider and can help identify the root cause.

Reproduced on 0.55.2. I think that this is due to a race condition. In our situation we are moving to a next screen when you’ve set a value using the slider. This causes two things to happen at the same time: indicator/seek button becomes smaller with an animation, but the screen is also rerendering, thus removing the slider. My theory is that the slider is being removed and the animation is called after it, causing the NullPointerException. (It happens rarely though).

Possible workaround could be:

  • Use another Slider
  • Disable the animation (not supported by react-native)
  • Move to the next screen/render the next elements slightly after the slider animation.

Simulator used: Nexus 5X with Android 7.0 and 7.1 and device: API 24 (7.0), 520x960 hdpi

Reproduced on 0.57.2 as well (Release Build) 😦

Android 7.0 in production Huawei (WAS-LX1A) React-Native 0.55.4

I m also facing the same problem, any one got this issue 's solution ?

Still here for us also. Happened a few days ago on HUAWEI KIW-L21, OS Level 23 WITH “react-native”: “0.48.2”

java.lang.NullPointerException: Attempt to write to field 'java.util.ArrayList android.animation.AnimatorSet$Node.nodeDependents' on a null object reference at android.animation.AnimatorSet.clone(AnimatorSet.java:700) at android.animation.AnimatorSet.clone(AnimatorSet.java:51) at android.animation.Animator$AnimatorConstantState.newInstance(Animator.java:562) at android.animation.Animator$AnimatorConstantState.newInstance(Animator.java:543) at android.content.res.ConstantState.newInstance(ConstantState.java:51) at android.content.res.ConstantState.newInstance(ConstantState.java:59) at android.content.res.ConfigurationBoundResourceCache.getInstance(ConfigurationBoundResourceCache.java:48) at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:111) at android.graphics.drawable.AnimatedVectorDrawable$AnimatedVectorDrawableState$PendingAnimator.newInstance(AnimatedVectorDrawable.java:567) at android.graphics.drawable.AnimatedVectorDrawable$AnimatedVectorDrawableState.inflatePendingAnimators(AnimatedVectorDrawable.java:545) at android.graphics.drawable.AnimatedVectorDrawable.applyTheme(AnimatedVectorDrawable.java:377) at android.graphics.drawable.DrawableContainer$DrawableContainerState.applyTheme(DrawableContainer.java:865) at android.graphics.drawable.DrawableContainer.applyTheme(DrawableContainer.java:577) at android.graphics.drawable.StateListDrawable.applyTheme(StateListDrawable.java:370) at android.graphics.drawable.AnimatedStateListDrawable.applyTheme(AnimatedStateListDrawable.java:391) at android.content.res.Resources.loadDrawable(Resources.java:4165) at android.content.res.Resources.loadDrawable(Resources.java:4006) at android.content.res.TypedArray.getDrawable(TypedArray.java:886) at android.content.res.XResources$XTypedArray.getDrawable(XResources.java:1372) at android.widget.AbsSeekBar.<init>(AbsSeekBar.java:194) at android.widget.SeekBar.<init>(SeekBar.java:85) at android.widget.SeekBar.<init>(SeekBar.java:81) at com.facebook.react.views.slider.ReactSlider.<init>(ReactSlider.java:56) at com.facebook.react.views.slider.ReactSliderManager.createViewInstance(ReactSliderManager.java:121) at com.facebook.react.views.slider.ReactSliderManager.createViewInstance(ReactSliderManager.java:39) at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:46) at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:218) at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:150) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.dispatchPendingNonBatchedOperations(UIViewOperationQueue.java:923) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:895) at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:31) at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:136) at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:107) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:909) at android.view.Choreographer.doCallbacks(Choreographer.java:686) at android.view.Choreographer.doFrame(Choreographer.java:619) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7407) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:133)