elharo opened a new pull request, #12630:
URL: https://github.com/apache/maven/pull/12630

   Fixes #12605
   
   ## Problem
   `DefaultProjectBuildingHelper.createProjectRealm()` was declared 
`synchronized`, making it a global lock during multi-module parallel builds. 
Every project needing extension realm setup had to acquire this lock serially.
   
   Additionally, `DefaultProjectRealmCache.put()` had a check-then-act race 
condition: `containsKey()` followed by `put()` are not atomic, allowing two 
threads to both pass the check and overwrite each other's entry.
   
   ## Fix
   1. **Removed `synchronized`** from `createProjectRealm()` — the 
`projectRealmCache` uses `ConcurrentHashMap` and is already thread-safe for 
`get`/`createKey`.
   2. **Fixed `put()` race** — replaced the non-atomic `containsKey()` + 
`put()` with `putIfAbsent()`, which atomically inserts only if absent and 
throws `IllegalStateException` if the key already exists.
   
   ## Testing
   Added `DefaultProjectRealmCacheTest` that verifies concurrent `put()` calls 
with the same key result in exactly one successful insertion.


-- 
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]

Reply via email to