Skip to content

[Android] Fix ConcurrentModificationException in InteropUIBlockListener #51631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,35 @@ internal class InteropUIBlockListener : UIManagerListener {
}

override fun willMountItems(uiManager: UIManager) {
if (beforeUIBlocks.isEmpty()) {
return
val blocksToExecute: List<UIBlock> = synchronized(this) {
if (beforeUIBlocks.isEmpty()) {
return
}
beforeUIBlocks.toList().also { beforeUIBlocks.clear() }
}
beforeUIBlocks.forEach {
if (uiManager is UIBlockViewResolver) {
it.execute(uiManager)

if (uiManager is UIBlockViewResolver) {
// avoid ConcurrentModificationException by iterating over a copy
blocksToExecute.forEach { block ->
block.execute(uiManager)
}
}
beforeUIBlocks.clear()
}

override fun didMountItems(uiManager: UIManager) {
if (afterUIBlocks.isEmpty()) {
return
val blocksToExecute: List<UIBlock> = synchronized(this) {
if (afterUIBlocks.isEmpty()) {
return
}
afterUIBlocks.toList().also { afterUIBlocks.clear() }
}
afterUIBlocks.forEach {
if (uiManager is UIBlockViewResolver) {
it.execute(uiManager)

if (uiManager is UIBlockViewResolver) {
// avoid ConcurrentModificationException by iterating over a copy
blocksToExecute.forEach { block ->
block.execute(uiManager)
}
}
afterUIBlocks.clear()
}

override fun didDispatchMountItems(uiManager: UIManager) = didMountItems(uiManager)
Expand Down
Loading