Program: 178206
Project: 178206
Buggy source:
/** 
 * Take the first remote change from the remoteQueue and process it
 */
private void processRemoteChange(){
  if (remoteQueue.isEmpty()) {
    return;
  }
  JSONObject remoteJSON=remoteQueue.remove(0);
  try {
    RemoteChange remoteChange=RemoteChange.buildFromMap(remoteJSON);
    log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion()));
    boolean acknowledged=false;
    Change change=pendingChanges.get(remoteChange.getKey());
    if (remoteChange.isAcknowledgedBy(change)) {
      log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion(),change.getChangeId()));
      serializer.onAcknowledgeChange(change);
      pendingChanges.remove(change.getKey());
      if (remoteChange.isError()) {
        Logger.log(TAG,String.format("String_Node_Str",remoteChange.getErrorCode(),remoteChange.getKey()));
        onError(remoteChange,change);
      }
 else {
        try {
          Ghost ghost=onAcknowledged(remoteChange,change);
          Change compressed=null;
          Iterator<Change> queuedChanges=localQueue.iterator();
          while (queuedChanges.hasNext()) {
            Change queuedChange=queuedChanges.next();
            if (queuedChange.getKey().equals(change.getKey())) {
              queuedChanges.remove();
              if (!remoteChange.isRemoveOperation()) {
                compressed=queuedChange.reapplyOrigin(ghost.getVersion(),ghost.getDiffableValue());
              }
            }
          }
          if (compressed != null) {
            localQueue.add(compressed);
          }
        }
 catch (        RemoteChangeInvalidException e) {
          Logger.log(TAG,"String_Node_Str",e);
          log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion(),e.getMessage()));
        }
      }
    }
 else {
      if (remoteChange.isError()) {
        Logger.log(TAG,String.format("String_Node_Str",remoteChange));
        log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion()));
      }
 else {
        try {
          onRemote(remoteChange);
          Logger.log(TAG,String.format("String_Node_Str",remoteChange.getChangeVersion()));
        }
 catch (        RemoteChangeInvalidException e) {
          Logger.log(TAG,"String_Node_Str",e);
          log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion(),e.getMessage()));
        }
      }
    }
    if (!remoteChange.isError() && remoteChange.isRemoveOperation()) {
      Iterator<Change> iterator=localQueue.iterator();
      while (iterator.hasNext()) {
        Change queuedChange=iterator.next();
        if (queuedChange.getKey().equals(remoteChange.getKey())) {
          iterator.remove();
        }
      }
    }
  }
 catch (  JSONException e) {
    Logger.log(TAG,"String_Node_Str",e);
    return;
  }
}

Fixed version (ground truth):
/** 
 * Take the first remote change from the remoteQueue and process it
 */
private void processRemoteChange(){
  if (remoteQueue.isEmpty()) {
    return;
  }
  JSONObject remoteJSON=remoteQueue.remove(0);
  try {
    RemoteChange remoteChange=RemoteChange.buildFromMap(remoteJSON);
    log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion()));
    Change change=pendingChanges.get(remoteChange.getKey());
    if (remoteChange.isAcknowledgedBy(change)) {
      log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion(),change.getChangeId()));
      serializer.onAcknowledgeChange(change);
      pendingChanges.remove(change.getKey());
      if (remoteChange.isError()) {
        Logger.log(TAG,String.format("String_Node_Str",remoteChange.getErrorCode(),remoteChange.getKey()));
        onError(remoteChange,change);
      }
 else {
        try {
          Ghost ghost=onAcknowledged(remoteChange,change);
          Change compressed=null;
          Iterator<Change> queuedChanges=localQueue.iterator();
          while (queuedChanges.hasNext()) {
            Change queuedChange=queuedChanges.next();
            if (queuedChange.getKey().equals(change.getKey())) {
              queuedChanges.remove();
              if (!remoteChange.isRemoveOperation()) {
                compressed=queuedChange.reapplyOrigin(ghost.getVersion(),ghost.getDiffableValue());
              }
            }
          }
          if (compressed != null) {
            localQueue.add(compressed);
          }
        }
 catch (        RemoteChangeInvalidException e) {
          Logger.log(TAG,"String_Node_Str",e);
          log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion(),e.getMessage()));
        }
      }
    }
 else {
      if (remoteChange.isError()) {
        Logger.log(TAG,String.format("String_Node_Str",remoteChange));
        log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion()));
      }
 else {
        try {
          onRemote(remoteChange);
          Logger.log(TAG,String.format("String_Node_Str",remoteChange.getChangeVersion()));
        }
 catch (        RemoteChangeInvalidException e) {
          Logger.log(TAG,"String_Node_Str",e);
          log(LOG_DEBUG,String.format("String_Node_Str",remoteChange.getChangeVersion(),e.getMessage()));
        }
      }
    }
    if (!remoteChange.isError() && remoteChange.isRemoveOperation()) {
      Iterator<Change> iterator=localQueue.iterator();
      while (iterator.hasNext()) {
        Change queuedChange=iterator.next();
        if (queuedChange.getKey().equals(remoteChange.getKey())) {
          iterator.remove();
        }
      }
    }
  }
 catch (  JSONException e) {
    Logger.log(TAG,"String_Node_Str",e);
  }
}