From cb5021f825ecb6749922e7a0cb53ca879726e51d Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Mon, 22 Apr 2024 16:24:01 +0800 Subject: [PATCH] fix:fix NullPointerException when properties contain kv with null value. --- changes/changes-1.13.0.md | 4 ++++ .../config/listener/PolarisConfigListenerContext.java | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 changes/changes-1.13.0.md diff --git a/changes/changes-1.13.0.md b/changes/changes-1.13.0.md new file mode 100644 index 00000000..48343737 --- /dev/null +++ b/changes/changes-1.13.0.md @@ -0,0 +1,4 @@ +# Change Log +--- + +- fix:fix NullPointerException when properties contain kv with null value. 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 00f1ecb8..120ef7c7 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);