Program: 178204
Project: 178204
Buggy source:
public Ghost applyRemoteChange(RemoteChange change) throws RemoteChangeInvalidException {
  Ghost updatedGhost=null;
  if (change.isRemoveOperation()) {
    try {
      removeObjectWithKey(change.getKey());
      ghostStore.deleteGhost(this,change.getKey());
    }
 catch (    BucketObjectMissingException e) {
      throw (new RemoteChangeInvalidException(change,e));
    }
  }
 else {
    try {
      T object=null;
      Boolean isNew=false;
      if (change.isAddOperation()) {
        object=newObject(change.getKey());
        isNew=true;
      }
 else {
        object=getObject(change.getKey());
        isNew=false;
        notifyOnBeforeUpdateObjectListeners(object);
      }
      Ghost ghost=object.getGhost();
      JSONObject localModifications=null;
      JSONObject currentProperties=ghost.getDiffableValue();
      try {
        localModifications=JSONDiff.diff(currentProperties,object.getDiffableValue());
      }
 catch (      JSONException e) {
        localModifications=new JSONObject();
      }
      updatedGhost=change.apply(ghost);
      JSONObject updatedProperties=JSONDiff.deepCopy(updatedGhost.getDiffableValue());
      ghostStore.saveGhost(this,updatedGhost);
      object.setGhost(updatedGhost);
      if (isNew) {
        schema.updateWithDefaults(object,updatedProperties);
        addObject(object);
      }
 else {
        if (localModifications != null && localModifications.length() > 0) {
          try {
            JSONObject incomingDiff=change.getPatch();
            JSONObject localDiff=localModifications.getJSONObject(JSONDiff.DIFF_VALUE_KEY);
            JSONObject transformedDiff=JSONDiff.transform(localDiff,incomingDiff,currentProperties);
            updatedProperties=JSONDiff.apply(currentProperties,transformedDiff);
          }
 catch (          JSONException e) {
          }
        }
        schema.update(object,updatedProperties);
        updateObject(object);
      }
    }
 catch (    SimperiumException e) {
      Logger.log(TAG,String.format("String_Node_Str",change),e);
      throw (new RemoteChangeInvalidException(change,e));
    }
  }
  setChangeVersion(change.getChangeVersion());
  change.setApplied();
  ChangeType type=change.isRemoveOperation() ? ChangeType.REMOVE : ChangeType.MODIFY;
  notifyOnNetworkChangeListeners(type,change.getKey());
  return updatedGhost;
}

Fixed version (ground truth):
public Ghost applyRemoteChange(RemoteChange change) throws RemoteChangeInvalidException {
  Ghost updatedGhost=null;
  if (change.isRemoveOperation()) {
    try {
      removeObjectWithKey(change.getKey());
      ghostStore.deleteGhost(this,change.getKey());
    }
 catch (    BucketObjectMissingException e) {
      throw (new RemoteChangeInvalidException(change,e));
    }
  }
 else {
    try {
      T object=null;
      Boolean isNew=false;
      if (change.isAddOperation()) {
        object=newObject(change.getKey());
        isNew=true;
      }
 else {
        object=getObject(change.getKey());
        isNew=false;
        notifyOnBeforeUpdateObjectListeners(object);
      }
      Ghost ghost=object.getGhost();
      JSONObject localModifications=null;
      JSONObject currentProperties=ghost.getDiffableValue();
      try {
        localModifications=JSONDiff.diff(currentProperties,object.getDiffableValue());
      }
 catch (      JSONException e) {
        localModifications=new JSONObject();
      }
      updatedGhost=change.apply(ghost);
      JSONObject updatedProperties=JSONDiff.deepCopy(updatedGhost.getDiffableValue());
      ghostStore.saveGhost(this,updatedGhost);
      object.setGhost(updatedGhost);
      if (isNew) {
        schema.updateWithDefaults(object,updatedProperties);
        addObject(object);
      }
 else {
        if (localModifications != null && localModifications.length() > 0) {
          try {
            JSONObject incomingDiff=change.getPatch();
            JSONObject localDiff=localModifications.getJSONObject(JSONDiff.DIFF_VALUE_KEY);
            JSONObject transformedDiff=JSONDiff.transform(localDiff,incomingDiff,currentProperties);
            updatedProperties=JSONDiff.apply(updatedProperties,transformedDiff);
          }
 catch (          JSONException e) {
          }
        }
        schema.update(object,updatedProperties);
        updateObject(object);
      }
    }
 catch (    SimperiumException e) {
      Logger.log(TAG,String.format("String_Node_Str",change),e);
      throw (new RemoteChangeInvalidException(change,e));
    }
  }
  setChangeVersion(change.getChangeVersion());
  change.setApplied();
  ChangeType type=change.isRemoveOperation() ? ChangeType.REMOVE : ChangeType.MODIFY;
  notifyOnNetworkChangeListeners(type,change.getKey());
  return updatedGhost;
}