Skip to content

Commit 8d78995

Browse files
artembilanspring-builds
authored andcommitted
GH-11042: Fix race condition in the ControlBusCommandRegistry (#11046)
* GH-11042: Fix race condition in the ControlBusCommandRegistry Fixes: #11042 The `ControlBusCommandRegistry` can be accessed (and populated) concurrently. Therefore, it is better to protect its internal from the `ConcurrentModificationException` * Use `ConcurrentHashMap` and `synchronized` in the `ControlBusCommandRegistry` whenever concurrent access is possible. * No need in `synchronized (this.controlBusCommands)` (cherry picked from commit f0a2f65)
1 parent e5606a9 commit 8d78995

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

spring-integration-core/src/main/java/org/springframework/integration/support/management/ControlBusCommandRegistry.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Objects;
2525
import java.util.Optional;
2626
import java.util.Set;
27+
import java.util.concurrent.ConcurrentHashMap;
2728
import java.util.function.Function;
2829
import java.util.regex.Matcher;
2930
import java.util.regex.Pattern;
@@ -70,7 +71,7 @@ public class ControlBusCommandRegistry
7071

7172
private static final ControlBusMethodFilter CONTROL_BUS_METHOD_FILTER = new ControlBusMethodFilter();
7273

73-
private final Map<String, Map<CommandMethod, Expression>> controlBusCommands = new HashMap<>();
74+
private final Map<String, Map<CommandMethod, Expression>> controlBusCommands = new ConcurrentHashMap<>();
7475

7576
private boolean eagerInitialization;
7677

@@ -193,7 +194,7 @@ private Expression populateCommandMethod(CommandMethod commandMethod,
193194
String beanName = commandMethod.beanName;
194195

195196
Map<CommandMethod, Expression> beanControlBusCommands =
196-
this.controlBusCommands.computeIfAbsent(beanName, (key) -> new HashMap<>());
197+
this.controlBusCommands.computeIfAbsent(beanName, (key) -> new ConcurrentHashMap<>());
197198

198199
try {
199200
return beanControlBusCommands.computeIfAbsent(commandMethod, mappingFunction);

0 commit comments

Comments
 (0)