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

timothyjward pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/aries-typedevent.git


The following commit(s) were added to refs/heads/main by this push:
     new 6f243b9  Fixed concurrent modification in wildcard history update
6f243b9 is described below

commit 6f243b986ef1eef5b0e47519b793fe7fe53af7ca
Author: Tim Ward <[email protected]>
AuthorDate: Mon Nov 30 11:59:20 2026 +0000

    Fixed concurrent modification in wildcard history update
    
    Widening a wildcard history policy removed entries from the map it was 
iterating over, so configureHistoryStorage threw and left the cleanup 
incomplete.
    
    Signed-off-by: Tim Ward <[email protected]>
---
 .../typedevent/bus/impl/TypedEventMonitorImpl.java      |  5 ++++-
 .../typedevent/bus/impl/TypedEventMonitorImplTest.java  | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git 
a/org.apache.aries.typedevent.bus/src/main/java/org/apache/aries/typedevent/bus/impl/TypedEventMonitorImpl.java
 
b/org.apache.aries.typedevent.bus/src/main/java/org/apache/aries/typedevent/bus/impl/TypedEventMonitorImpl.java
index 2ae1aa1..4fa0ff3 100644
--- 
a/org.apache.aries.typedevent.bus/src/main/java/org/apache/aries/typedevent/bus/impl/TypedEventMonitorImpl.java
+++ 
b/org.apache.aries.typedevent.bus/src/main/java/org/apache/aries/typedevent/bus/impl/TypedEventMonitorImpl.java
@@ -367,14 +367,17 @@ public class TypedEventMonitorImpl implements 
TypedEventMonitor {
                                        Consumer<String> action = (min > 0 || 
max < historySize) ?
                                                        s -> 
updateRestrictedHistory(s, min, max) :
                                                        
topicsWithRestrictedHistories::remove;
+                                       // The action may remove from the map, 
so collect the topics first
+                                       List<String> affected = new 
ArrayList<>();
                                        for(Entry<String, TopicHistory> e : 
topicsWithRestrictedHistories.entrySet()) {
                                                
if(key.matchesTopic(e.getKey())) {
                                                        RangePolicy 
effectivePolicy = getEffectiveHistoryStorage(e.getKey());
                                                        
if(!e.getValue().policyMatches(effectivePolicy)) {
-                                                               
action.accept(e.getKey());
+                                                               
affected.add(e.getKey());
                                                        }
                                                }
                                        }
+                                       affected.forEach(action);
                                }
                        } else if(min > 0 || max < historySize){
                                updateRestrictedHistory(topicFilter, min, max);
diff --git 
a/org.apache.aries.typedevent.bus/src/test/java/org/apache/aries/typedevent/bus/impl/TypedEventMonitorImplTest.java
 
b/org.apache.aries.typedevent.bus/src/test/java/org/apache/aries/typedevent/bus/impl/TypedEventMonitorImplTest.java
index 8b286bb..bd62aee 100644
--- 
a/org.apache.aries.typedevent.bus/src/test/java/org/apache/aries/typedevent/bus/impl/TypedEventMonitorImplTest.java
+++ 
b/org.apache.aries.typedevent.bus/src/test/java/org/apache/aries/typedevent/bus/impl/TypedEventMonitorImplTest.java
@@ -126,6 +126,23 @@ public class TypedEventMonitorImplTest {
                        () -> checkRangeConfiguration(TOPIC_PATTERN_SINGLE, 
TOPIC, RangePolicy.range(1,Integer.MAX_VALUE)));
     }
 
+    /**
+     * Tests that widening a wildcard history policy, which discards the 
restricted
+     * histories of the topics it covers, does not fail while doing so
+     * 
+     * @throws InterruptedException
+     */
+    @Test
+    public void testWildcardReconfigurationDiscardsRestrictedHistories() 
throws InterruptedException {
+        monitorImpl.configureHistoryStorage("*", RangePolicy.atMost(1));
+
+        monitorImpl.event("a/b", Collections.<String, 
Object>singletonMap("key", "1"));
+        monitorImpl.event("c/d", Collections.<String, 
Object>singletonMap("key", "2"));
+
+        monitorImpl.configureHistoryStorage("*", RangePolicy.unlimited());
+        assertEquals(RangePolicy.unlimited(), 
monitorImpl.getConfiguredHistoryStorage("*"));
+    }
+
     @Test
     public void testTooBig() {
        int total = monitorImpl.getMaximumEventStorage();

Reply via email to