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

ahuber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/main by this push:
     new 31fc0da17bf CAUSEWAY-3937: fixes ConcurrentMapWrapper to not throw
31fc0da17bf is described below

commit 31fc0da17bfec3e2226e765de69a91f284a36289
Author: andi-huber <[email protected]>
AuthorDate: Sun Jan 25 18:04:08 2026 +0100

    CAUSEWAY-3937: fixes ConcurrentMapWrapper to not throw
    
    IllegalState Recursive update
---
 .../core/metamodel/services/grid/GridCache.java     | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/grid/GridCache.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/grid/GridCache.java
index e566bb76a12..28e65eec99f 100644
--- 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/grid/GridCache.java
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/grid/GridCache.java
@@ -90,23 +90,14 @@ public Try<BSGrid> computeIfAbsent(final LayoutKey 
layoutKey, final Function<Lay
     ..
     at 
org.apache.causeway.core.metamodel.util.Facets.gridPreload(Facets.java:200)*/
     record ConcurrentMapWrapper<K, V>(ConcurrentHashMap<K, V> map) {
-
         public V computeIfAbsent(final K key, final 
java.util.function.Function<? super K, ? extends V> mappingFunction) {
-            // Use an atomic flag to track whether a recursive call is 
currently happening.
-            // It ensures that multiple threads can manage their recursion 
state independently.
-            final ThreadLocal<Boolean> isRecursing = 
ThreadLocal.withInitial(() -> false);
-
-            // Define a recursive compute function
-            return map.compute(key, (k, v) -> {
-                if (isRecursing.get()) return v; // return current value if 
already in recursion
+            var value = map.get(key);
+            if(value!=null)
+                return value;
 
-                isRecursing.set(true); // mark as in recursion
-                try {
-                    return v == null ? mappingFunction.apply(k) : v;
-                } finally {
-                    isRecursing.remove(); // clean up the flag variable
-                }
-            });
+            var newValue = mappingFunction.apply(key);
+            map.put(key, newValue);
+            return newValue;
         }
     }
 

Reply via email to