Program: 13166
Project: 13166
Buggy source:
/** 
 * Patches the given resource and will also remove private properties if it is an external call based upon context.
 * @param context
 * @param request
 * @param resource The resource to be patched
 * @param revision
 * @param patchOperations
 * @return The patched ResourceResponse with private properties omitted if called externally.
 * @throws ResourceException
 */
private ResourceResponse patchResource(Context context,Request request,ResourceResponse resource,String revision,List<PatchOperation> patchOperations) throws ResourceException {
  boolean forceUpdate=(revision == null);
  boolean retry=forceUpdate;
  String rev=revision;
  do {
    logger.debug("String_Node_Str",name,request.getResourcePath());
    try {
      JsonValue decrypted=decrypt(resource.getContent());
      if (revision == null) {
        rev=decrypted.get("String_Node_Str").asString();
      }
      JsonValue newValue=decrypted.copy();
      boolean modified=JsonValuePatch.apply(newValue,patchOperations);
      if (!modified) {
        return null;
      }
      if (enforcePolicies) {
        ActionRequest policyAction=Requests.newActionRequest(ResourcePath.valueOf("String_Node_Str").concat(managedId(resource.getId())).toString(),"String_Node_Str");
        policyAction.setContent(newValue);
        if (ContextUtil.isExternal(context)) {
          policyAction.setAdditionalParameter("String_Node_Str","String_Node_Str");
        }
        JsonValue result=connectionFactory.getConnection().action(context,policyAction).getJsonContent();
        if (!result.isNull() && !result.get("String_Node_Str").asBoolean()) {
          logger.debug("String_Node_Str",result);
          throw new ForbiddenException("String_Node_Str").setDetail(result);
        }
      }
      ResourceResponse patchedResource=update(context,request,resource.getId(),rev,resource.getContent(),newValue);
      activityLogger.log(context,request,"String_Node_Str",managedId(patchedResource.getId()).toString(),resource.getContent(),patchedResource.getContent(),Status.SUCCESS);
      retry=false;
      logger.debug("String_Node_Str");
      return prepareResponse(context,patchedResource,request.getFields());
    }
 catch (    PreconditionFailedException e) {
      if (forceUpdate) {
        logger.debug("String_Node_Str");
      }
 else {
        throw e;
      }
    }
catch (    ResourceException e) {
      throw e;
    }
  }
 while (retry);
  return null;
}

Fixed version (ground truth):
/** 
 * Patches the given resource and will also remove private properties if it is an external call based upon context.
 * @param context
 * @param request
 * @param resource The resource to be patched
 * @param revision
 * @param patchOperations
 * @return The patched ResourceResponse with private properties omitted if called externally.
 * @throws ResourceException
 */
private ResourceResponse patchResource(Context context,Request request,ResourceResponse resource,String revision,List<PatchOperation> patchOperations) throws ResourceException {
  boolean forceUpdate=(revision == null);
  boolean retry=forceUpdate;
  String rev=revision;
  do {
    logger.debug("String_Node_Str",name,request.getResourcePath());
    try {
      JsonValue decrypted=decrypt(resource.getContent());
      if (revision == null) {
        rev=decrypted.get("String_Node_Str").asString();
      }
      final JsonValue relationships=fetchRelationshipFields(context,resource.getId());
      decrypted.asMap().putAll(relationships.asMap());
      JsonValue newValue=decrypted.copy();
      boolean modified=JsonValuePatch.apply(newValue,patchOperations);
      if (!modified) {
        return null;
      }
      if (enforcePolicies) {
        ActionRequest policyAction=Requests.newActionRequest(ResourcePath.valueOf("String_Node_Str").concat(managedId(resource.getId())).toString(),"String_Node_Str");
        policyAction.setContent(newValue);
        if (ContextUtil.isExternal(context)) {
          policyAction.setAdditionalParameter("String_Node_Str","String_Node_Str");
        }
        JsonValue result=connectionFactory.getConnection().action(context,policyAction).getJsonContent();
        if (!result.isNull() && !result.get("String_Node_Str").asBoolean()) {
          logger.debug("String_Node_Str",result);
          throw new ForbiddenException("String_Node_Str").setDetail(result);
        }
      }
      ResourceResponse patchedResource=update(context,request,resource.getId(),rev,resource.getContent(),newValue);
      activityLogger.log(context,request,"String_Node_Str",managedId(patchedResource.getId()).toString(),resource.getContent(),patchedResource.getContent(),Status.SUCCESS);
      retry=false;
      logger.debug("String_Node_Str");
      return prepareResponse(context,patchedResource,request.getFields());
    }
 catch (    PreconditionFailedException e) {
      if (forceUpdate) {
        logger.debug("String_Node_Str");
      }
 else {
        throw e;
      }
    }
catch (    ResourceException e) {
      throw e;
    }
catch (    Exception e) {
      throw new InternalServerErrorException(e.getMessage(),e);
    }
  }
 while (retry);
  return null;
}