Skip to content

GH-1789 - Use ConcurrentHashMap for the module dependency cache. - #1790

Open
arendomoda wants to merge 2 commits into
spring-projects:mainfrom
arendomoda:patch-1
Open

GH-1789 - Use ConcurrentHashMap for the module dependency cache.#1790
arendomoda wants to merge 2 commits into
spring-projects:mainfrom
arendomoda:patch-1

Conversation

@arendomoda

Copy link
Copy Markdown

Fixes #1789

TestExecutionCondition.evaluate(…) is called concurrently when junit.jupiter.execution.parallel.mode.classes.default=concurrent is configured, so computeIfAbsent on the plain HashMap can fail with a ConcurrentModificationException. Switching to ConcurrentHashMap keeps the caching behaviour and makes the field safe for concurrent access; ApplicationModule.getAllDependencies(…) never returns null, so the map's null-hostility is not a concern.

Observed on 2.0.6 with 74 of 602 test classes failing per run (different classes each time). No regression test added: reproducing the race deterministically isn't practical. Happy to add a stress test if you'd prefer one.

Signed-off-by: Arend van Erk arend.vanerk@omoda.nl

…ncy cache.

Fixes spring-projects#1789

`TestExecutionCondition.evaluate(…)` is called concurrently when
`junit.jupiter.execution.parallel.mode.classes.default=concurrent` is configured,
so `computeIfAbsent` on the plain `HashMap` can fail with a
`ConcurrentModificationException`. Switching to `ConcurrentHashMap` keeps the
caching behaviour and makes the field safe for concurrent access;
`ApplicationModule.getAllDependencies(…)` never returns `null`, so the map's
null-hostility is not a concern.

Observed on 2.0.6 with 74 of 602 test classes failing per run (different classes
each time). No regression test added: reproducing the race deterministically
isn't practical. Happy to add a stress test if you'd prefer one.

Signed-off-by: arendomoda <arend.vanerk@omoda.nl>
Signed-off-by: arendomoda <arend.vanerk@omoda.nl>
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.

ConcurrentModificationException in TestExecutionCondition when running tests with JUnit parallel class execution

1 participant