Repository: pinpoint-apm/pinpoint
Issue: fixed possibility of npe in ZookeeperClusterDataManager.
Labels: bug

fixed possibility of npe.

Conditions
- If ZookeeperClusterDataManager's process method invoke, before ZookeeperClient constructor has completed.


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/DefaultZookeeperClient.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/DefaultZookeeperClient.java
index cf7a4b75e313..99ba6bb91079 100644
--- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/DefaultZookeeperClient.java
+++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/DefaultZookeeperClient.java
@@ -23,7 +23,6 @@
 import com.navercorp.pinpoint.collector.cluster.zookeeper.exception.PinpointZookeeperException;
 import com.navercorp.pinpoint.collector.cluster.zookeeper.exception.TimeoutException;
 import com.navercorp.pinpoint.collector.cluster.zookeeper.exception.UnknownException;
-import com.navercorp.pinpoint.common.util.concurrent.CommonState;
 import com.navercorp.pinpoint.common.util.concurrent.CommonStateContext;
 import com.navercorp.pinpoint.rpc.util.TimerFactory;
 import org.apache.zookeeper.CreateMode;
@@ -92,7 +91,7 @@ public void connect() throws IOException {
 
     @Override
     public void reconnectWhenSessionExpired() {
-        if (stateContext.getCurrentState() != CommonState.STARTED) {
+        if (!stateContext.isStarted()) {
             logger.warn("ZookeeperClient.reconnectWhenSessionExpired() failed. Error: Already closed.");
             return;
         }
@@ -111,7 +110,7 @@ public void reconnectWhenSessionExpired() {
         }
         
         ZooKeeper newZookeeper = createNewZookeeper();
-        if (stateContext.getCurrentState() != CommonState.STARTED) {
+        if (!stateContext.isStarted()) {
             logger.warn("ZookeeperClient.reconnectWhenSessionExpired() failed. Error: Already closed.");
             return;
         }
@@ -277,7 +276,7 @@ private void checkState() throws PinpointZookeeperException {
 
     @Override
     public boolean isConnected() {
-        if (!watcher.isConnected() || stateContext.getCurrentState() != CommonState.STARTED) {
+        if (!watcher.isConnected() || !stateContext.isStarted()) {
             return false;
         }
 
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClient.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClient.java
index 8d5c4cfddfdc..d68f804b23e1 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClient.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClient.java
@@ -17,7 +17,6 @@
 package com.navercorp.pinpoint.web.cluster.zookeeper;
 
 
-import com.navercorp.pinpoint.common.util.concurrent.CommonState;
 import com.navercorp.pinpoint.common.util.concurrent.CommonStateContext;
 import com.navercorp.pinpoint.rpc.util.TimerFactory;
 import com.navercorp.pinpoint.web.cluster.zookeeper.exception.AuthException;
@@ -94,7 +93,7 @@ public void connect() throws IOException {
     }
 
     public void reconnectWhenSessionExpired() {
-        if (stateContext.getCurrentState() != CommonState.STARTED) {
+        if (!stateContext.isStarted()) {
             logger.warn("ZookeeperClient.reconnectWhenSessionExpired() failed. Error: Already closed.");
             return;
         }
@@ -259,7 +258,7 @@ public boolean exists(String path) throws PinpointZookeeperException, Interrupte
     }
 
     private void checkState() throws PinpointZookeeperException {
-        if (!zookeeperDataManager.isConnected() || stateContext.getCurrentState() != CommonState.STARTED) {
+        if (!zookeeperDataManager.isConnected() || !stateContext.isStarted()) {
             throw new ConnectionException("Instance must be connected.");
         }
     }


Test patch: