diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java index 0b6e8346c85ec..73f52a7214dbe 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java @@ -231,7 +231,10 @@ public ServerCnx(PulsarService pulsar) { } public ServerCnx(PulsarService pulsar, String listenerName) { - super(pulsar.getBrokerService().getKeepAliveIntervalSeconds(), TimeUnit.SECONDS); + // pulsar.getBrokerService() can sometimes be null in unit tests when using mocks + // the null check is a workaround for #13620 + super(pulsar.getBrokerService() != null ? pulsar.getBrokerService().getKeepAliveIntervalSeconds() : 0, + TimeUnit.SECONDS); this.service = pulsar.getBrokerService(); this.schemaService = pulsar.getSchemaRegistryService(); this.listenerName = listenerName;