Skip to content

Commit 805b88c

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Fix possible ConcurrentModificationException when accessing the list of view managers (#35770)
Summary: With the current implementation, it's possible to get a reference to the list of view managers while it's being populated, which in some cases results in `ConcurrentModificationException` thrown [here](https://github.com/facebook/react-native/blob/9c57a7f20925765da69590256ca8755b71735cdb/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java#L80). This PR updates the logic, so the reference to the list is updated (and returned) only when it's ready. ## Changelog [ANDROID] [FIXED] - Fix possible `ConcurrentModificationException` in `UIManagerModuleConstantsHelper::createConstants` Pull Request resolved: #35770 Reviewed By: cortinico Differential Revision: D42342107 Pulled By: rshest fbshipit-source-id: 8d799535c811edeefa1903fbf7a46bff22691e59
1 parent 9c57a7f commit 805b88c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,10 +923,11 @@ public List<ViewManager> getOrCreateViewManagers(
923923
if (mViewManagers == null) {
924924
synchronized (mPackages) {
925925
if (mViewManagers == null) {
926-
mViewManagers = new ArrayList<>();
926+
ArrayList<ViewManager> viewManagers = new ArrayList<>();
927927
for (ReactPackage reactPackage : mPackages) {
928-
mViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
928+
viewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
929929
}
930+
mViewManagers = viewManagers;
930931
return mViewManagers;
931932
}
932933
}

0 commit comments

Comments
 (0)