Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
[fix][broker] Fix NPE when update topic properties.
Browse files Browse the repository at this point in the history
### Motivation

In Pulsar 2.10, when creating a producer/consumer that auto-creates a topic and then attempts to update its properties, a NullPointerException (NPE) occurs. The reason is that Pulsar 2.10 does not correctly handle the case when the properties are `null`.
### Modifications

Add an NPE check.

(cherry picked from commit 0b02321)
  • Loading branch information
liangyepianzhou committed Sep 27, 2023
1 parent 28ecbde commit 337fdab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,8 @@ private void checkOwnershipAndCreatePersistentTopic(final String topic, boolean
pulsar.getNamespaceService().isServiceUnitActiveAsync(topicName)
.thenAccept(isActive -> {
if (isActive) {
createPersistentTopic(topic, createIfMissing, topicFuture, properties);
createPersistentTopic(topic, createIfMissing, topicFuture,
properties == null ? new HashMap<>() : properties);
} else {
// namespace is being unloaded
String msg = String.format("Namespace is being unloaded, cannot add topic %s", topic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -178,6 +179,19 @@ public void testTopicPolicyInitialValueWithNamespaceAlreadyLoaded() throws Excep
}


@Test
public void updatePropertiesForAutoCreatedTopicTest() throws Exception {
TopicName topicName = TopicName.get(
TopicDomain.persistent.value(),
NamespaceName.get(myNamespace),
"test-" + UUID.randomUUID()
);
String testTopic = topicName.toString();
Producer<byte[]> producer = pulsarClient.newProducer().topic(testTopic).create();
HashMap<String, String> properties = new HashMap<>();
properties.put("backlogQuotaType", "message_age");
admin.topics().updateProperties(testTopic, properties);
}
@Test
public void testSetSizeBasedBacklogQuota() throws Exception {

Expand Down

0 comments on commit 337fdab

Please sign in to comment.