소스 검색

[ 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 {
 public class ZooKeeper {
-    Watcher watcher;
+    volatile Watcher watcher;
 
 
     public enum States {
     public enum States {
         CONNECTING, ASSOCIATING, CONNECTED, CLOSED, AUTH_FAILED;
         CONNECTING, ASSOCIATING, CONNECTED, CLOSED, AUTH_FAILED;
@@ -119,16 +119,16 @@ public class ZooKeeper {
 
 
     public ZooKeeper(String host, int sessionTimeout, Watcher watcher)
     public ZooKeeper(String host, int sessionTimeout, Watcher watcher)
             throws KeeperException, IOException {
             throws KeeperException, IOException {
-        cnxn = new ClientCnxn(host, sessionTimeout, this);
         this.watcher = watcher;
         this.watcher = watcher;
+        cnxn = new ClientCnxn(host, sessionTimeout, this);
     }
     }
 
 
     public ZooKeeper(String host, int sessionTimeout, Watcher watcher,
     public ZooKeeper(String host, int sessionTimeout, Watcher watcher,
             long sessionId, byte[] sessionPasswd) throws KeeperException,
             long sessionId, byte[] sessionPasswd) throws KeeperException,
             IOException {
             IOException {
+        this.watcher = watcher;
         cnxn = new ClientCnxn(host, sessionTimeout, this, sessionId,
         cnxn = new ClientCnxn(host, sessionTimeout, this, sessionId,
                 sessionPasswd);
                 sessionPasswd);
-        this.watcher = watcher;
     }
     }
 
 
     public long getSessionId() {
     public long getSessionId() {