Program: 79416
Project: 79416
Buggy source:
protected synchronized void onServerPoolMemberChanged(Entity member){
  if (log.isTraceEnabled())   log.trace("String_Node_Str",new Object[]{this,member,member.getLocations()});
  Map<Entity,String> nodes=getAttribute(RIAK_CLUSTER_NODES);
  if (belongsInServerPool(member)) {
    if (nodes == null) {
      nodes=Maps.newLinkedHashMap();
    }
    String riakName=getRiakName(member);
    Preconditions.checkNotNull(riakName);
    if (!isFirstNodeSet.getAndSet(true)) {
      nodes.put(member,riakName);
      setAttribute(RIAK_CLUSTER_NODES,nodes);
      ((EntityInternal)member).setAttribute(RiakNode.RIAK_NODE_HAS_JOINED_CLUSTER,Boolean.TRUE);
      log.info("String_Node_Str",new Object[]{this,member,getRiakName(member)});
    }
 else {
      Optional<Entity> anyNodeInCluster=Iterables.tryFind(nodes.keySet(),new Predicate<Entity>(){
        @Override public boolean apply(        @Nullable Entity node){
          return (node instanceof RiakNode && hasMemberJoinedCluster(node));
        }
      }
);
      if (anyNodeInCluster.isPresent()) {
        if (!nodes.containsKey(member) && !hasMemberJoinedCluster(member)) {
          String anyNodeName=anyNodeInCluster.get().getAttribute(RiakNode.RIAK_NODE_NAME);
          Entities.invokeEffectorWithArgs(this,member,RiakNode.JOIN_RIAK_CLUSTER,anyNodeName);
          if (getAttribute(IS_CLUSTER_INIT)) {
            Entities.invokeEffector(RiakClusterImpl.this,anyNodeInCluster.get(),RiakNode.COMMIT_RIAK_CLUSTER);
          }
          nodes.put(member,riakName);
          setAttribute(RIAK_CLUSTER_NODES,nodes);
          log.info("String_Node_Str",new Object[]{this,member,getRiakName(member)});
        }
      }
 else {
        log.error("String_Node_Str",member.getId());
      }
    }
  }
 else {
    if (nodes != null && nodes.containsKey(member)) {
      final Entity memberToBeRemoved=member;
      Optional<Entity> anyNodeInCluster=Iterables.tryFind(nodes.keySet(),new Predicate<Entity>(){
        @Override public boolean apply(        @Nullable Entity node){
          return (node instanceof RiakNode && hasMemberJoinedCluster(node) && !node.equals(memberToBeRemoved));
        }
      }
);
      if (anyNodeInCluster.isPresent()) {
        Entities.invokeEffectorWithArgs(this,anyNodeInCluster.get(),RiakNode.LEAVE_RIAK_CLUSTER,getRiakName(memberToBeRemoved));
      }
      nodes.remove(member);
      setAttribute(RIAK_CLUSTER_NODES,nodes);
      log.info("String_Node_Str",new Object[]{this,member,getRiakName(member)});
    }
  }
  ServiceNotUpLogic.updateNotUpIndicatorRequiringNonEmptyMap(this,RIAK_CLUSTER_NODES);
  if (log.isTraceEnabled())   log.trace("String_Node_Str",this,member);
  calculateClusterAddresses();
}

Fixed version (ground truth):
protected void onServerPoolMemberChanged(Entity member){
synchronized (mutex) {
    log.trace("String_Node_Str",new Object[]{this,member,member.getLocations()});
    Map<Entity,String> nodes=getAttribute(RIAK_CLUSTER_NODES);
    if (belongsInServerPool(member)) {
      if (nodes == null) {
        nodes=Maps.newLinkedHashMap();
      }
      String riakName=getRiakName(member);
      Preconditions.checkNotNull(riakName);
      Boolean firstNode=getAttribute(IS_FIRST_NODE_SET);
      if (!Boolean.TRUE.equals(firstNode)) {
        setAttribute(IS_FIRST_NODE_SET,Boolean.TRUE);
        nodes.put(member,riakName);
        setAttribute(RIAK_CLUSTER_NODES,nodes);
        ((EntityInternal)member).setAttribute(RiakNode.RIAK_NODE_HAS_JOINED_CLUSTER,Boolean.TRUE);
        log.info("String_Node_Str",new Object[]{this,member,getRiakName(member)});
      }
 else {
        Optional<Entity> anyNodeInCluster=Iterables.tryFind(nodes.keySet(),new Predicate<Entity>(){
          @Override public boolean apply(          @Nullable Entity node){
            return (node instanceof RiakNode && hasMemberJoinedCluster(node));
          }
        }
);
        if (anyNodeInCluster.isPresent()) {
          if (!nodes.containsKey(member) && !hasMemberJoinedCluster(member)) {
            String anyNodeName=anyNodeInCluster.get().getAttribute(RiakNode.RIAK_NODE_NAME);
            Entities.invokeEffectorWithArgs(this,member,RiakNode.JOIN_RIAK_CLUSTER,anyNodeName);
            if (getAttribute(IS_CLUSTER_INIT)) {
              Entities.invokeEffector(RiakClusterImpl.this,anyNodeInCluster.get(),RiakNode.COMMIT_RIAK_CLUSTER);
            }
            nodes.put(member,riakName);
            setAttribute(RIAK_CLUSTER_NODES,nodes);
            log.info("String_Node_Str",new Object[]{this,member,getRiakName(member)});
          }
        }
 else {
          log.error("String_Node_Str",member.getId());
        }
      }
    }
 else {
      if (nodes != null && nodes.containsKey(member)) {
        final Entity memberToBeRemoved=member;
        Optional<Entity> anyNodeInCluster=Iterables.tryFind(nodes.keySet(),new Predicate<Entity>(){
          @Override public boolean apply(          @Nullable Entity node){
            return (node instanceof RiakNode && hasMemberJoinedCluster(node) && !node.equals(memberToBeRemoved));
          }
        }
);
        if (anyNodeInCluster.isPresent()) {
          Entities.invokeEffectorWithArgs(this,anyNodeInCluster.get(),RiakNode.LEAVE_RIAK_CLUSTER,getRiakName(memberToBeRemoved));
        }
        nodes.remove(member);
        setAttribute(RIAK_CLUSTER_NODES,nodes);
        log.info("String_Node_Str",new Object[]{this,member,getRiakName(member)});
      }
    }
    ServiceNotUpLogic.updateNotUpIndicatorRequiringNonEmptyMap(this,RIAK_CLUSTER_NODES);
    if (log.isTraceEnabled())     log.trace("String_Node_Str",this,member);
    calculateClusterAddresses();
  }
}