Fix ConcurrentModificationException in IntentModule.getInitialURL re-entrancy#57667
Open
nickcernera wants to merge 1 commit into
Open
Fix ConcurrentModificationException in IntentModule.getInitialURL re-entrancy#57667nickcernera wants to merge 1 commit into
nickcernera wants to merge 1 commit into
Conversation
|
@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this in D113595327. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
IntentModule.onHostResume()iteratespendingOpenURLPromises(anArrayList) directly and callsgetInitialURL()for each pending promise. WhengetCurrentActivity()returnsnullat that moment — e.g. a deep link or notification tap landing mid activity-transition during a rapid pause/resume —getInitialURL()re-enterswaitForActivityAndGetInitialURL(), which callspendingOpenURLPromises.add(promise)on the very list being iterated. The next iteration then throwsjava.util.ConcurrentModificationException:The
synchronized(this@IntentModule)guard does not prevent this: the re-entrancy is on the same thread, which already holds the (reentrant) lock, so no second lock acquisition happens. The crash is theArrayListiterator'smodCountcheck, not a cross-thread race.The fix snapshots the pending promises into a local copy, clears the shared list, and nulls the listener before draining. Re-queued promises then land in the now-empty
pendingOpenURLPromisesand register a fresh listener for the next resume, instead of mutating the list being iterated. Behaviour is otherwise unchanged.Changelog:
[ANDROID] [FIXED] - Fix ConcurrentModificationException when getInitialURL re-enters during onHostResume
Test Plan:
Added
IntentModuleTest.getInitialURL_onHostResumeWithNullActivity_doesNotThrowAndPreservesPromise, a Robolectric regression test that registers a pending promise while the current activity isnull, then drivesonHostResumeso the drain re-queues, and asserts the drain does not throw and the promise is preserved (neither resolved nor rejected).Ran locally against
mainwith the exact reproduction scenario:With the fix — passes:
Without the fix (reverting
IntentModule.ktonly) — fails with the exact crash, confirming the test is a genuine regression test:ktfmt(Meta style, matching the repo'sktfmtconfiguration) reports both changed files as already formatted.