From 537679f894f868abbe07b1e494d6b6829b0519d6 Mon Sep 17 00:00:00 2001 From: Flowermin <48741608+Flowermin@users.noreply.github.com> Date: Wed, 31 Aug 2022 15:38:40 +0800 Subject: [PATCH] [fix][broker] Fix NPE when updating topic's properties (#17352) Co-authored-by: bjhuxiaohua (cherry picked from commit f1d11586e96344c40cab923f0ed89961d673cd5c) --- .../pulsar/broker/admin/impl/PersistentTopicsBase.java | 3 ++- .../org/apache/pulsar/broker/admin/AdminApi2Test.java | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java index ad75e723707a6..26170bb56f8c5 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java @@ -675,7 +675,8 @@ protected CompletableFuture internalUpdatePropertiesAsync(boolean authorit return namespaceResources() .getPartitionedTopicResources().updatePartitionedTopicAsync(topicName, p -> new PartitionedTopicMetadata(p.partitions, - MapUtils.putAll(p.properties, properties.entrySet().toArray()))); + p.properties == null ? properties + : MapUtils.putAll(p.properties, properties.entrySet().toArray()))); }); } }).thenAccept(__ -> diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java index cb186ce256af2..d84fab7137f86 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java @@ -909,11 +909,14 @@ public void testUpdatePartitionedTopicProperties() throws Exception { final String topicNameTwo = "persistent://" + namespace + "/testUpdatePartitionedTopicProperties2"; admin.namespaces().createNamespace(namespace, 20); - // create partitioned topic with properties + // create partitioned topic without properties + admin.topics().createPartitionedTopic(topicName, 2); + Map properties = admin.topics().getProperties(topicName); + Assert.assertNull(properties); Map topicProperties = new HashMap<>(); topicProperties.put("key1", "value1"); - admin.topics().createPartitionedTopic(topicName, 2, topicProperties); - Map properties = admin.topics().getProperties(topicName); + admin.topics().updateProperties(topicName, topicProperties); + properties = admin.topics().getProperties(topicName); Assert.assertNotNull(properties); Assert.assertEquals(properties.get("key1"), "value1");