Skip to content

Commit

Permalink
Fix possible ConcurrentModificationException when accessing the lis…
Browse files Browse the repository at this point in the history
…t 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
  • Loading branch information
j-piasecki authored and facebook-github-bot committed Jan 4, 2023
1 parent 9c57a7f commit 805b88c
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,11 @@ public List<ViewManager> getOrCreateViewManagers(
if (mViewManagers == null) {
synchronized (mPackages) {
if (mViewManagers == null) {
mViewManagers = new ArrayList<>();
ArrayList<ViewManager> viewManagers = new ArrayList<>();
for (ReactPackage reactPackage : mPackages) {
mViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
viewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
}
mViewManagers = viewManagers;
return mViewManagers;
}
}
Expand Down

0 comments on commit 805b88c

Please sign in to comment.