Description
In what version(s) of Spring Integration are you seeing this issue?
spring-integration-redis:6.2.1
Describe the bug
By looking at the RedisLockRegistry (https://github.com/spring-projects/spring-integration/blob/main/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java), the setExecutor method attempts to set the
this.redisMessageListenerContainer.setTaskExecutor(this.executor);
this.redisMessageListenerContainer.setSubscriptionExecutor(this.executor);
Since redisMessgeListenerContainer is lazy initialised, it's likely that the setExecutor method will fail since it does not have any null checking for this.redisMessageListenerContainer.
To Reproduce
If you run the below code snippet the execution will fail due to a NullPointerException (
RedisLockRegistry redisLockRegistry =
new RedisLockRegistry(redisConnectionFactory, lockRegistryKey):
redisLockRegistry.setRedisLockType(RedisLockRegistry.RedisLockType.PUB_SUB_LOCK);
redisLockRegistry.setExecutor(Executors.newFixedThreadPool(100));
Expected behavior
I would expect that setting the executor will have a null check for redisMessageListenerContainer as shown in the code below: -
public void setExecutor(Executor executor) {
this.executor = executor;
this.executorExplicitlySet = true;
if (this.redisMessageListenerContainer != null) {
this.redisMessageListenerContainer.setTaskExecutor(this.executor);
this.redisMessageListenerContainer.setSubscriptionExecutor(this.executor);
}
}
Sample
RedisLockRegistry redisLockRegistry =
new RedisLockRegistry(redisConnectionFactory, lockRegistryKey):
redisLockRegistry.setRedisLockType(RedisLockRegistry.RedisLockType.PUB_SUB_LOCK);
redisLockRegistry.setExecutor(Executors.newFixedThreadPool(100));