[android] Dismissing a modal can sometimes result in a NPE
See original GitHub issueIs this a bug report?
This is a bug seen sometimes when dismissing modals on android
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getId()' on a null object reference
at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:531)
at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:425)
at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:179)
at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:768)
at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:824)
at com.facebook.react.uimanager.UIViewOperationQueue.access$1600(UIViewOperationQueue.java:48)
at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:870)
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:723)
at android.view.Choreographer.doFrame(Choreographer.java:655)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Have you read the Contributing Guidelines?
Yes
Environment
react-native: 0.47.2 => 0.47.2 react: 16.0.0-alpha.12 => 16.0.0-alpha.12
Target Platform: Android (seems to only happen on O - i’ve only seen this on pixel devices)
Steps to Reproduce
This is kind of a difficult one to actually reproduce, as it seems to be related to a race condition. I’ve seen this a few times now from instabug.
- Show a Modal
- Dismiss a modal
- see crash (above)
Expected Behavior
App does not crash
Actual Behavior
App Crashes
Proposed cause
It appears that
is calling
by removing the hostview from the parent and dismissing the dialog, our view object is being mutated in some way.
I think it would be smart to hold onto view.getId() before calling onDropInstance then use that to clean up the rest of our views. I’m not entirely sure how this works at this level,
Proposed changes
/**
* Releases all references to given native View.
*/
protected synchronized void dropView(View view) {
UiThreadUtil.assertOnUiThread();
int viewId = view.getId();
if (!mRootTags.get(viewId)) {
// For non-root views we notify viewmanager with {@link ViewManager#onDropInstance}
resolveViewManager(viewId).onDropViewInstance(view);
}
ViewManager viewManager = mTagsToViewManagers.get(viewId);
if (view instanceof ViewGroup && viewManager instanceof ViewGroupManager) {
ViewGroup viewGroup = (ViewGroup) view;
ViewGroupManager viewGroupManager = (ViewGroupManager) viewManager;
for (int i = viewGroupManager.getChildCount(viewGroup) - 1; i >= 0; i--) {
View child = viewGroupManager.getChildAt(viewGroup, i);
if (mTagsToViews.get(child.getId()) != null) {
dropView(child);
}
}
viewGroupManager.removeAllViews(viewGroup);
}
mTagsToViews.remove(viewId);
mTagsToViewManagers.remove(viewId);
}
I’d be happy to submit this change if this seems like the right way to go.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
I have the same issue on a note 8 running Oreo
I have the same crash stack !!