This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 877bf3a Fix NPE in checkSubscriptionTypesEnable (#12961)
877bf3a is described below
commit 877bf3a34e72336c05706ffd48826e4347606196
Author: Zike Yang <[email protected]>
AuthorDate: Fri Nov 26 11:23:12 2021 +0800
Fix NPE in checkSubscriptionTypesEnable (#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:
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
```
### Modifications
* Use `CollectionUtils.isEmpty` to determine if the list is empty to fix
the problem of throwing NPE.
---
.../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 5c94e61..415a988 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.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.broker.PulsarServerException;
@@ -3232,7 +3233,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);