From d030cb3d24e6a32b17058a751300c9c8cbe33001 Mon Sep 17 00:00:00 2001 From: yanrongzhen Date: Sat, 15 Apr 2023 18:54:41 +0800 Subject: [PATCH] Fix: DynamicThreadPoolAdapterRegister NPE during application startup --- .../support/DynamicThreadPoolAdapterRegister.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolAdapterRegister.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolAdapterRegister.java index 8e10b255..42c66d23 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolAdapterRegister.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolAdapterRegister.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.InitializingBean; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL; @@ -55,10 +56,13 @@ public class DynamicThreadPoolAdapterRegister implements InitializingBean { } public void discoverAdapterExecutor() { - List adapterExecutors = bootstrapConfigProperties.getAdapterExecutors(); - for (AdapterExecutorProperties each : adapterExecutors) { - String buildKey = each.getMark() + IDENTIFY_SLICER_SYMBOL + each.getThreadPoolKey(); - ADAPTER_EXECUTORS_MAP.putIfAbsent(buildKey, each); - } + Optional> adapterExecutorProperties = + Optional.ofNullable(bootstrapConfigProperties.getAdapterExecutors()); + adapterExecutorProperties.ifPresent(props -> { + for (AdapterExecutorProperties each : props) { + String buildKey = each.getMark() + IDENTIFY_SLICER_SYMBOL + each.getThreadPoolKey(); + ADAPTER_EXECUTORS_MAP.putIfAbsent(buildKey, each); + } + }); } }