Program: 48112
Project: 48112
Buggy source:
private boolean checkReplicaSyncState(){
  if (!initialized || !node.joined()) {
    return true;
  }
  if (getMemberGroupsSize() < 2) {
    return true;
  }
  final Address thisAddress=node.getThisAddress();
  final Semaphore s=new Semaphore(0);
  final AtomicBoolean ok=new AtomicBoolean(true);
  final Callback<Object> callback=new Callback<Object>(){
    @Override public void notify(    Object object){
      if (Boolean.FALSE.equals(object)) {
        ok.compareAndSet(true,false);
      }
 else       if (object instanceof Throwable) {
        ok.compareAndSet(true,false);
      }
      s.release();
    }
  }
;
  int notOwnedCount=0;
  for (  InternalPartitionImpl partition : partitions) {
    Address owner=partition.getOwner();
    if (thisAddress.equals(owner)) {
      if (partition.getReplicaAddress(1) != null) {
        SyncReplicaVersion op=new SyncReplicaVersion(1,callback);
        op.setService(this);
        op.setNodeEngine(nodeEngine);
        op.setResponseHandler(ResponseHandlerFactory.createErrorLoggingResponseHandler(node.getLogger(SyncReplicaVersion.class)));
        op.setPartitionId(partition.getPartitionId());
        nodeEngine.getOperationService().executeOperation(op);
      }
 else {
        ok.set(false);
        s.release();
      }
    }
 else {
      if (owner == null) {
        ok.set(false);
      }
      notOwnedCount++;
    }
  }
  s.release(notOwnedCount);
  try {
    if (ok.get()) {
      return s.tryAcquire(partitionCount,10,TimeUnit.SECONDS) && ok.get();
    }
 else {
      return false;
    }
  }
 catch (  InterruptedException ignored) {
    return false;
  }
}

Fixed version (ground truth):
private boolean checkReplicaSyncState(){
  if (!initialized) {
    return true;
  }
  if (getMemberGroupsSize() < 2) {
    return true;
  }
  final Address thisAddress=node.getThisAddress();
  final Semaphore s=new Semaphore(0);
  final AtomicBoolean ok=new AtomicBoolean(true);
  final Callback<Object> callback=new Callback<Object>(){
    @Override public void notify(    Object object){
      if (Boolean.FALSE.equals(object)) {
        ok.compareAndSet(true,false);
      }
 else       if (object instanceof Throwable) {
        ok.compareAndSet(true,false);
      }
      s.release();
    }
  }
;
  int notOwnedCount=0;
  for (  InternalPartitionImpl partition : partitions) {
    Address owner=partition.getOwner();
    if (thisAddress.equals(owner)) {
      if (partition.getReplicaAddress(1) != null) {
        SyncReplicaVersion op=new SyncReplicaVersion(1,callback);
        op.setService(this);
        op.setNodeEngine(nodeEngine);
        op.setResponseHandler(ResponseHandlerFactory.createErrorLoggingResponseHandler(node.getLogger(SyncReplicaVersion.class)));
        op.setPartitionId(partition.getPartitionId());
        nodeEngine.getOperationService().executeOperation(op);
      }
 else {
        ok.set(false);
        s.release();
      }
    }
 else {
      if (owner == null) {
        ok.set(false);
      }
      notOwnedCount++;
    }
  }
  s.release(notOwnedCount);
  try {
    if (ok.get()) {
      return s.tryAcquire(partitionCount,10,TimeUnit.SECONDS) && ok.get();
    }
 else {
      return false;
    }
  }
 catch (  InterruptedException ignored) {
    return false;
  }
}