Repository: apache/fluo
Issue: Seeing spurious NPE in worker logs

Saw the following exception in worker logs while testing 1.1.0-SNAP.  I was using commit 4055cdfbe13eb34f8830db3ba2201c6428d26fd4

I think at [Oracle client line 117][1] that `leaderSelector` needs to be created before stating `pathChildrenCache`


[1]: https://github.com/apache/incubator-fluo/blob/4055cdfbe13eb34f8830db3ba2201c6428d26fd4/modules/core/src/main/java/org/apache/fluo/core/oracle/OracleClient.java#L117

```
java.lang.NullPointerException: null
        at org.apache.fluo.core.oracle.OracleClient$TimestampRetriever.childEvent(OracleClient.java:145) ~[fluo-core-1.1.0-incubating-SNAPSHOT.jar:1.1.0-incubating-SNAPSHOT]
        at org.apache.curator.framework.recipes.cache.PathChildrenCache$5.apply(PathChildrenCache.java:516) [curator-recipes-2.7.1.jar:na]
        at org.apache.curator.framework.recipes.cache.PathChildrenCache$5.apply(PathChildrenCache.java:510) [curator-recipes-2.7.1.jar:na]
        at org.apache.curator.framework.listen.ListenerContainer$1.run(ListenerContainer.java:92) [curator-framework-2.7.1.jar:na]
        at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:262) [guava-13.0.1.jar:na]
        at org.apache.curator.framework.listen.ListenerContainer.forEach(ListenerContainer.java:84) [curator-framework-2.7.1.jar:na]
        at org.apache.curator.framework.recipes.cache.PathChildrenCache.callListeners(PathChildrenCache.java:508) [curator-recipes-2.7.1.jar:na]
        at org.apache.curator.framework.recipes.cache.EventOperation.invoke(EventOperation.java:35) [curator-recipes-2.7.1.jar:na]
        at org.apache.curator.framework.recipes.cache.PathChildrenCache$9.run(PathChildrenCache.java:759) [curator-recipes-2.7.1.jar:na]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_131]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_131]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_131]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_131]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
```

Changed files:
modules/core/src/main/java/org/apache/fluo/core/oracle/OracleClient.java

diff --git a/modules/core/src/main/java/org/apache/fluo/core/oracle/OracleClient.java b/modules/core/src/main/java/org/apache/fluo/core/oracle/OracleClient.java
index 66a0c9e6..d8eaed4c 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/oracle/OracleClient.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/oracle/OracleClient.java
@@ -111,13 +111,13 @@ public class OracleClient implements AutoCloseable {
             Thread.sleep(200);
           }
 
+          leaderSelector = new LeaderSelector(curatorFramework, ZookeeperPath.ORACLE_SERVER, this);
+
           pathChildrenCache =
               new PathChildrenCache(curatorFramework, ZookeeperPath.ORACLE_SERVER, true);
           pathChildrenCache.getListenable().addListener(this);
           pathChildrenCache.start();
 
-          leaderSelector = new LeaderSelector(curatorFramework, ZookeeperPath.ORACLE_SERVER, this);
-
           connect();
         }
         doWork();