From 1e2f01b28b40ac6df568884a5453883088c8ae81 Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Mon, 6 Mar 2023 16:11:47 +0800 Subject: [PATCH] fix:fix NPE. (#885) --- CHANGELOG.md | 1 + .../feign/DefaultEnhancedFeignPluginRunner.java | 14 ++++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e5ea3962..b04f0a495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,3 +13,4 @@ - [optimize:optimize ServiceRuleManager.](https://github.com/Tencent/spring-cloud-tencent/pull/878) - [refactor:refactor stat module.](https://github.com/Tencent/spring-cloud-tencent/pull/879) - [feature:add polaris circuit breaker support.](https://github.com/Tencent/spring-cloud-tencent/pull/881) +- [fix:fix NPE.](https://github.com/Tencent/spring-cloud-tencent/pull/885) diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/DefaultEnhancedFeignPluginRunner.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/DefaultEnhancedFeignPluginRunner.java index affce002a..dbaf7d580 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/DefaultEnhancedFeignPluginRunner.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/DefaultEnhancedFeignPluginRunner.java @@ -18,12 +18,11 @@ package com.tencent.cloud.rpc.enhancement.feign; -import java.util.ArrayList; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignContext; import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPlugin; import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPluginType; @@ -37,18 +36,13 @@ import org.springframework.util.CollectionUtils; */ public class DefaultEnhancedFeignPluginRunner implements EnhancedFeignPluginRunner { - private Map> pluginMap = new HashMap<>(); + private final Multimap pluginMap = ArrayListMultimap.create(); public DefaultEnhancedFeignPluginRunner(List enhancedFeignPlugins) { if (!CollectionUtils.isEmpty(enhancedFeignPlugins)) { enhancedFeignPlugins.stream() .sorted(Comparator.comparing(EnhancedFeignPlugin::getOrder)) - .forEach(plugin -> { - if (!pluginMap.containsKey(plugin.getType().name())) { - pluginMap.put(plugin.getType().name(), new ArrayList<>()); - } - pluginMap.get(plugin.getType().name()).add(plugin); - }); + .forEach(plugin -> pluginMap.put(plugin.getType().name(), plugin)); } }