This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit d9a1b876578dc8b1ead736bc3c5753a35954d9c8
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sun Jun 7 09:45:45 2026 +0000

    Fix WeakInternPool — synchronize compute on map
    
    Collections.synchronizedMap does not make compute() atomic; the
    default Map.compute implementation performs a non-atomic read-modify
    sequence, risking concurrent structural modification of the underlying
    WeakHashMap.
    
    Wrap the compute() call in synchronized(map) to use the same monitor
    that synchronizedMap uses internally.
---
 .../aether/internal/impl/collect/DataPool.java     | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java
index 84095e09c..463dcf804 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java
@@ -567,17 +567,19 @@ public final class DataPool {
         @SuppressWarnings("unchecked")
         public V intern(K key, V value) {
             Object[] result = new Object[1];
-            map.compute(key, (k, existingRef) -> {
-                if (existingRef != null) {
-                    V pooled = existingRef.get();
-                    if (pooled != null) {
-                        result[0] = pooled;
-                        return existingRef;
+            synchronized (map) {
+                map.compute(key, (k, existingRef) -> {
+                    if (existingRef != null) {
+                        V pooled = existingRef.get();
+                        if (pooled != null) {
+                            result[0] = pooled;
+                            return existingRef;
+                        }
                     }
-                }
-                result[0] = value;
-                return new WeakReference<>(value);
-            });
+                    result[0] = value;
+                    return new WeakReference<>(value);
+                });
+            }
             return (V) result[0];
         }
     }

Reply via email to