You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2021/11/26 13:10:25 UTC
[pulsar] 14/14: Fix NPE in checkSubscriptionTypesEnable (#12961)
This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 4522fc144a7f3a278663a418efa1fc712d2895f5
Author: Zike Yang <ar...@armail.top>
AuthorDate: Fri Nov 26 11:23:12 2021 +0800
Fix NPE in checkSubscriptionTypesEnable (#12961)
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: https://github.com/apache/pulsar/pull/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
```
* Use `CollectionUtils.isEmpty` to determine if the list is empty to fix the problem of throwing NPE.
(cherry picked from commit 877bf3a34e72336c05706ffd48826e4347606196)
---
.../org/apache/pulsar/broker/service/persistent/PersistentTopic.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
index 5e884ea..e1c2983 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
@@ -73,6 +73,7 @@ import org.apache.bookkeeper.mledger.impl.ManagedCursorImpl;
import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
import org.apache.bookkeeper.mledger.impl.PositionImpl;
import org.apache.bookkeeper.net.BookieId;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.broker.PulsarServerException;
import org.apache.pulsar.broker.ServiceConfiguration;
@@ -3206,7 +3207,7 @@ public class PersistentTopic extends AbstractTopic
if (topicPolicies == null) {
return checkNsAndBrokerSubscriptionTypesEnable(topicName, subType);
} else {
- if (topicPolicies.getSubscriptionTypesEnabled().isEmpty()) {
+ if (CollectionUtils.isEmpty(topicPolicies.getSubscriptionTypesEnabled())) {
return checkNsAndBrokerSubscriptionTypesEnable(topicName, subType);
}
return topicPolicies.getSubscriptionTypesEnabled().contains(subType);