From 1cb56931e71bd2f61063a5e9ebbfd1bbb23ad040 Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Thu, 25 Apr 2024 19:12:59 +0800 Subject: [PATCH] fix:fix NullPointerException when properties contain kv with null value. --- CHANGELOG.md | 1 + pom.xml | 2 +- .../config/listener/PolarisConfigListenerContext.java | 8 ++++++++ spring-cloud-tencent-dependencies/pom.xml | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bae0b7100..d4069ddae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,3 +22,4 @@ - [fix:fix sct-all wrong spring boot version obtain.](https://github.com/Tencent/spring-cloud-tencent/pull/1206) - [fix:fix reporter wrong initialization when using config data.](https://github.com/Tencent/spring-cloud-tencent/pull/1220) - [fix:fix restTemplateCustomizer bean conflict causing service to fail to start properly](https://github.com/Tencent/spring-cloud-tencent/pull/1238) +- fix:fix NullPointerException when properties contain kv with null value. diff --git a/pom.xml b/pom.xml index 49cad0170..8c11aae9c 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ - 1.13.1-2022.0.4 + 1.13.2-2022.0.4 6.0.16 diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigListenerContext.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigListenerContext.java index 00f1ecb85..120ef7c73 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigListenerContext.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigListenerContext.java @@ -116,6 +116,11 @@ public final class PolarisConfigListenerContext { * @param ret origin properties map */ static void initialize(Map ret) { + for (Map.Entry entry : ret.entrySet()) { + if (entry.getValue() == null) { + ret.put(entry.getKey(), ""); + } + } properties.putAll(ret); } @@ -142,6 +147,9 @@ public final class PolarisConfigListenerContext { ret.keySet().parallelStream().forEach(key -> { Object oldValue = properties.getIfPresent(key); Object newValue = ret.get(key); + if (newValue == null) { + newValue = ""; + } if (oldValue != null) { if (!newValue.equals(oldValue)) { properties.put(key, newValue); diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index 0c03a65c0..b3d7c64ee 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -70,7 +70,7 @@ - 1.13.1-2022.0.4 + 1.13.2-2022.0.4 1.15.0