Program: 13176
Project: 13176
Buggy source:
/** 
 * Update a resource as part of an update or patch request.
 * @param context the current Context
 * @param request the source Request
 * @param resourceId the resource id of the object being modified
 * @param rev the revision of hte object being modified
 * @param oldValue the old value of the object
 * @param newValue the new value of the object
 * @return a {@link ResourceResponse} object representing the updated resource
 * @throws ResourceException
 */
private ResourceResponse update(final Context context,Request request,String resourceId,String rev,JsonValue oldValue,JsonValue newValue) throws ResourceException {
  if (newValue.asMap().equals(oldValue.asMap())) {
    return newResourceResponse(resourceId,rev,null);
  }
  final JsonValue persistRelationships=persistRelationships(context,resourceId,newValue);
  newValue.asMap().putAll(persistRelationships.asMap());
  execScript(context,ScriptHook.onUpdate,newValue,prepareScriptBindings(context,request,resourceId,oldValue,newValue));
  populateVirtualProperties(context,newValue);
  newValue=stripRelationshipFields(newValue);
  onStore(context,newValue);
  UpdateRequest updateRequest=Requests.newUpdateRequest(repoId(resourceId),newValue);
  updateRequest.setRevision(rev);
  ResourceResponse response=connectionFactory.getConnection().update(context,updateRequest);
  response.getContent().asMap().putAll(persistRelationships.asMap());
  execScript(context,ScriptHook.postUpdate,response.getContent(),prepareScriptBindings(context,request,resourceId,oldValue,response.getContent()));
  performSyncAction(context,request,resourceId,SynchronizationService.SyncServiceAction.notifyUpdate,oldValue,response.getContent());
  return response;
}

Fixed version (ground truth):
/** 
 * Update a resource as part of an update or patch request.
 * @param context the current Context
 * @param request the source Request
 * @param resourceId the resource id of the object being modified
 * @param rev the revision of hte object being modified
 * @param oldValue the old value of the object
 * @param newValue the new value of the object
 * @return a {@link ResourceResponse} object representing the updated resource
 * @throws ResourceException
 */
private ResourceResponse update(final Context context,Request request,String resourceId,String rev,JsonValue oldValue,JsonValue newValue) throws ResourceException {
  if (newValue.asMap().equals(oldValue.asMap())) {
    return newResourceResponse(resourceId,rev,null);
  }
  newValue.asMap().putAll(persistRelationships(context,resourceId,newValue).asMap());
  execScript(context,ScriptHook.onUpdate,newValue,prepareScriptBindings(context,request,resourceId,oldValue,newValue));
  populateVirtualProperties(context,newValue);
  JsonValue strippedRelationshipFields=stripRelationshipFields(newValue);
  onStore(context,newValue);
  UpdateRequest updateRequest=Requests.newUpdateRequest(repoId(resourceId),newValue);
  updateRequest.setRevision(rev);
  ResourceResponse response=connectionFactory.getConnection().update(context,updateRequest);
  response.getContent().asMap().putAll(strippedRelationshipFields.asMap());
  execScript(context,ScriptHook.postUpdate,response.getContent(),prepareScriptBindings(context,request,resourceId,oldValue,response.getContent()));
  performSyncAction(context,request,resourceId,SynchronizationService.SyncServiceAction.notifyUpdate,oldValue,response.getContent());
  return response;
}