Skip to content

Commit 1565634

Browse files
alpha0010facebook-github-bot
authored andcommitted
Resolve android crash on display modal (#35380)
Summary: From exception logging, found crashes due to `Attempt to invoke virtual method 'int android.view.ViewGroup.getChildCount()' on a null object reference`. Tracing through the stack, it appears the constructor for `ViewGroup` conditionally calls `initializeScrollbarsInternal()`, which in turn calls `getChildCount()`. However `ReactModalHostView` overrides `getChildCount()`, so `getChildCount()` is called before `ReactModalHostView` constructor completes, resulting in null reference when accessing `mHostView` from `getChildCount()`. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Android] [Fixed] - Fix crash on initialize modal Pull Request resolved: #35380 Test Plan: In the rn-tester project, display a modal. Reviewed By: javache, cipolleschi Differential Revision: D41392235 Pulled By: ryancat fbshipit-source-id: ce78e4d458ad41769e78139ea0a8a038384e830d
1 parent 4d7ddd4 commit 1565634

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ public void addView(View child, int index) {
120120

121121
@Override
122122
public int getChildCount() {
123-
return mHostView.getChildCount();
123+
// This method may be called by the parent constructor
124+
// before mHostView is initialized.
125+
return mHostView == null ? 0 : mHostView.getChildCount();
124126
}
125127

126128
@Override

0 commit comments

Comments
 (0)