Github user dragonsinth commented on a diff in the pull request:

    https://github.com/apache/curator/pull/250#discussion_r167672355
  
    --- Diff: 
curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
 ---
    @@ -397,14 +396,11 @@ public void processResult(CuratorFramework client, 
CuratorEvent event) throws Ex
                             break;
                         }
     
    -                    ConcurrentMap<String, TreeNode> childMap = children;
    -                    if ( childMap == null )
    +                    ConcurrentMap<String, TreeNode> childMap;
    +                    while ( (childMap = children) == null )
                         {
                             childMap = Maps.newConcurrentMap();
    -                        if ( !childrenUpdater.compareAndSet(this, null, 
childMap) )
    -                        {
    -                            childMap = children;
    -                        }
    +                        if ( childrenUpdater.compareAndSet(this, null, 
childMap) ) break;
    --- End diff --
    
    I see why you turned this into a loop (nice catch), but I think it reads a 
little clearly and more deliberateif you revert back to the original code and 
just change the `if` -> `while`.  Ideally if Curator moves wholesale to Java 
1.8,  funcs, like:
    
    ```
                        ConcurrentMap<String, TreeNode> childMap = 
childrenUpdater.updateAndGet(this, (oldChildren) -> {
                            return oldChildren != null ? oldChildren : 
Maps.newConcurrentMap();
                        });
    ```


---

Reply via email to