gnodet opened a new pull request, #12865: URL: https://github.com/apache/maven/pull/12865
## Summary - **Removed `synchronized`** from `DefaultProjectBuildingHelper.createProjectRealm()` which was serializing all extension realm setup across projects in parallel builds - **Fixed TOCTOU race conditions** in three cache classes (`DefaultProjectRealmCache`, `DefaultExtensionRealmCache`, `DefaultPluginArtifactsCache`) by replacing the non-atomic `containsKey()` + `put()` with `ConcurrentHashMap.putIfAbsent()` - **Added redundant realm disposal** in both `createProjectRealm()` and `setupExtensionsRealm()` to clean up ClassRealms when another thread wins the cache race ## Context This is an alternative to #12630 which correctly identified the bottleneck but introduced a TOCTOU race condition at the caller level (as noted in the review). This PR addresses the review feedback by: 1. Using `putIfAbsent()` in the caches so the put operation is atomic — no `IllegalStateException` under contention 2. Having callers detect when `putIfAbsent` returns an existing record (via identity check `record.getRealm() != projectRealm`) and dispose the redundant realm 3. Also fixing `DefaultExtensionRealmCache` and `DefaultPluginArtifactsCache` which have the same check-then-act race and are exposed to concurrent access once the `synchronized` is removed ## Test plan - [x] Added `DefaultProjectRealmCacheTest` with concurrent `putIfAbsent` test (8 threads, CyclicBarrier for maximum contention) - [x] All 614 maven-core module tests pass - [x] Full reactor build succeeds 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
