Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix NPE in checkSubscriptionTypesEnable (apache#12961)
### Motivation The NPE may appear in `PersistentTopic.checkSubscriptionTypesEnable`. The `topicPolicies.getSubscriptionTypesEnabled()` may be null. The problem occurred when upgrading from pulsar version 2.7 to 2.8. We added `SubscriptionTypesEnable` in 2.8: apache#9401. When we initialize a topic's topicPolicy in pulasr 2.7, and then get the topic's topicPolicy in version 2.8, the `SubscriptionTypesEnable` will be null. This leads to the problem. Here are steps to reproduce: * Start broker 2.7 * Create a topic and init the topic policy * Upgrade broker to 2.8 * We will get the `SubscriptionTypesEnable` with the value of null ```sh ➜ pulsar-281 bin/pulsar-admin topics get-subscription-types-enabled my-topic null ``` * When we consume from that topic, the issue occurs ``` Caused by: java.lang.NullPointerException at org.apache.pulsar.broker.service.persistent.PersistentTopic.checkSubscriptionTypesEnable(PersistentTopic.java:3206) ~[io.streamnative-pulsar-broker-2.8.1.21.jar:2.8.1.21] at org.apache.pulsar.broker.service.persistent.PersistentTopic.subscribe(PersistentTopic.java:688) ~[io.streamnative-pulsar-broker-2.8.1.21.jar:2.8.1.21] at org.apache.pulsar.broker.service.ServerCnx.lambda$null$13(ServerCnx.java:1029) ~[io.streamnative-pulsar-broker-2.8.1.21.jar:2.8.1.21] at java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1106) ~[?:?] ... 31 more ``` ### Modifications * Use `CollectionUtils.isEmpty` to determine if the list is empty to fix the problem of throwing NPE.
- Loading branch information