This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.9 by this push:
     new 4691d3e  Add null check to workaround NPE in unit tests with 
Mockito/PowerMock (#14006)
4691d3e is described below

commit 4691d3e80c0afc2b31e15023263247d171b7a696
Author: Lari Hotari <[email protected]>
AuthorDate: Fri Jan 28 22:01:21 2022 +0200

    Add null check to workaround NPE in unit tests with Mockito/PowerMock 
(#14006)
    
    - Fixes #13620
    
    (cherry picked from commit e45b4f211db43cdbf604a6dfc5bf305b541b0702)
---
 .../src/main/java/org/apache/pulsar/broker/service/ServerCnx.java    | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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 9f317be..189c079 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
@@ -230,7 +230,10 @@ public class ServerCnx extends PulsarHandler implements 
TransportCnx {
     }
 
     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;

Reply via email to