From 6d64b6ebb8319da73353ac545fb060d4127b58c4 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 31 Oct 2024 13:23:44 -0400 Subject: [PATCH] GH-9623: Fix `ThreadStatePropagationChannelInterceptor` for concurrency Fixes: #9623 Issue link: https://github.com/spring-projects/spring-integration/issues/9623 The `ConcurrentModificationException` is thrown from the `ThreadStatePropagationChannelInterceptor.MessageWithThreadState.stateQueue` which is a not thread-safe `LinkedList` * Fix `ThreadStatePropagationChannelInterceptor.MessageWithThreadState.stateQueue` to be a `LinkedBlockingQueue` instead (cherry picked from commit ba57ee8a1b98efa19ece2686961713925b8246cb) --- .../ThreadStatePropagationChannelInterceptor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/ThreadStatePropagationChannelInterceptor.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/ThreadStatePropagationChannelInterceptor.java index 19408c21249..21cbeecbe1a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/ThreadStatePropagationChannelInterceptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/ThreadStatePropagationChannelInterceptor.java @@ -16,8 +16,8 @@ package org.springframework.integration.channel.interceptor; -import java.util.LinkedList; import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; import io.micrometer.common.lang.Nullable; @@ -105,14 +105,14 @@ private static final class MessageWithThreadState implements Message, Me private final Queue stateQueue; MessageWithThreadState(Message message, Object state) { - this(message, new LinkedList<>()); + this(message, new LinkedBlockingQueue<>()); this.stateQueue.add(state); } @SuppressWarnings("unchecked") private MessageWithThreadState(Message message, Queue stateQueue) { this.message = (Message) message; - this.stateQueue = new LinkedList<>(stateQueue); + this.stateQueue = new LinkedBlockingQueue<>(stateQueue); } @Override