Skip to content

Commit 62fd3e6

Browse files
Neville Bonaviaartembilan
Neville Bonavia
authored andcommitted
GH-8869: Fix NPE in RedisLockRegistry.setExecutor
Fixes: #8869 Do not set the `redisMessageListenerContainer`'s executor in the setter method since the Redis Message Listener container is not initialised during configuration due to lazy loading **Cherry-pick to `6.2.x` & `6.0.x`**
1 parent 35f3a87 commit 62fd3e6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -198,8 +198,6 @@ private void setupUnlockMessageListener(RedisConnectionFactory connectionFactory
198198
public void setExecutor(Executor executor) {
199199
this.executor = executor;
200200
this.executorExplicitlySet = true;
201-
this.redisMessageListenerContainer.setTaskExecutor(this.executor);
202-
this.redisMessageListenerContainer.setSubscriptionExecutor(this.executor);
203201
}
204202

205203
/**

spring-integration-redis/src/test/java/org/springframework/integration/redis/util/RedisLockRegistryTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@
4141
import org.junit.jupiter.api.AfterEach;
4242
import org.junit.jupiter.api.BeforeAll;
4343
import org.junit.jupiter.api.BeforeEach;
44+
import org.junit.jupiter.api.Test;
4445
import org.junit.jupiter.params.ParameterizedTest;
4546
import org.junit.jupiter.params.provider.EnumSource;
4647

@@ -52,6 +53,8 @@
5253

5354
import static org.assertj.core.api.Assertions.assertThat;
5455
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
56+
import static org.assertj.core.api.Assertions.assertThatNoException;
57+
import static org.mockito.Mockito.mock;
5558

5659
/**
5760
* @author Gary Russell
@@ -875,6 +878,13 @@ void testTwoThreadsRemoveAndObtainSameLockSimultaneously(RedisLockType testRedis
875878
registry.destroy();
876879
}
877880

881+
@Test
882+
void testInitialiseWithCustomExecutor() {
883+
RedisLockRegistry redisLockRegistry = new RedisLockRegistry(redisConnectionFactory, "registryKey");
884+
redisLockRegistry.setRedisLockType(RedisLockType.PUB_SUB_LOCK);
885+
assertThatNoException().isThrownBy(() -> redisLockRegistry.setExecutor(mock()));
886+
}
887+
878888
private Long getExpire(RedisLockRegistry registry, String lockKey) {
879889
StringRedisTemplate template = createTemplate();
880890
String registryKey = TestUtils.getPropertyValue(registry, "registryKey", String.class);

0 commit comments

Comments
 (0)