Skip to content

Fix race condition in inline static mocking - #213

Open
the-felipeal wants to merge 1 commit into
linkedin:mainfrom
the-felipeal:fix-static-mock-race
Open

Fix race condition in inline static mocking#213
the-felipeal wants to merge 1 commit into
linkedin:mainfrom
the-felipeal:fix-static-mock-race

Conversation

@the-felipeal

Copy link
Copy Markdown

InlineStaticMockMaker, StaticMockMethodAdvice, and StaticMockitoSession previously tracked active static mocks using standard HashMap instances. When background threads executed methods on instrumented classes (such as Thread.onSpinWait()) while test threads were concurrently creating or resetting static mocks, iterating over classToMarker.keySet() threw
ConcurrentModificationException.

Switch internal mock tracking maps to ConcurrentHashMap and sessions list to CopyOnWriteArrayList, and add null safety guards to map lookups to eliminate this race condition.

InlineStaticMockMaker, StaticMockMethodAdvice, and
StaticMockitoSession previously tracked active static mocks using
standard HashMap instances. When background threads executed methods
on instrumented classes (such as Thread.onSpinWait()) while test
threads were concurrently creating or resetting static mocks,
iterating over classToMarker.keySet() threw
ConcurrentModificationException.

Switch internal mock tracking maps to ConcurrentHashMap and sessions
list to CopyOnWriteArrayList, and add null safety guards to map
lookups to eliminate this race condition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant