浏览代码

[ 1958361 ] Patch to fix NPE upon access to watcher

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@670943 13f79535-47bb-0310-9956-ffa450edef68
Benjamin Reed 17 年之前
父节点
当前提交
afd85358e0
共有 1 个文件被更改,包括 3 次插入3 次删除
  1. 3 3
      zookeeper/java/src/com/yahoo/zookeeper/ZooKeeper.java

+ 3 - 3
zookeeper/java/src/com/yahoo/zookeeper/ZooKeeper.java

@@ -103,7 +103,7 @@ import com.yahoo.zookeeper.server.DataTree;
  * 
  */
 public class ZooKeeper {
-    Watcher watcher;
+    volatile Watcher watcher;
 
     public enum States {
         CONNECTING, ASSOCIATING, CONNECTED, CLOSED, AUTH_FAILED;
@@ -119,16 +119,16 @@ public class ZooKeeper {
 
     public ZooKeeper(String host, int sessionTimeout, Watcher watcher)
             throws KeeperException, IOException {
-        cnxn = new ClientCnxn(host, sessionTimeout, this);
         this.watcher = watcher;
+        cnxn = new ClientCnxn(host, sessionTimeout, this);
     }
 
     public ZooKeeper(String host, int sessionTimeout, Watcher watcher,
             long sessionId, byte[] sessionPasswd) throws KeeperException,
             IOException {
+        this.watcher = watcher;
         cnxn = new ClientCnxn(host, sessionTimeout, this, sessionId,
                 sessionPasswd);
-        this.watcher = watcher;
     }
 
     public long getSessionId() {