Program: 115490
Project: 115490
Buggy source:
/** 
 * Update deployment policy
 * @param deploymentPolicyDefinitionBean DeploymentPolicyBean
 * @throws RestAPIException
 */
public static void updateDeploymentPolicy(DeploymentPolicyBean deploymentPolicyDefinitionBean) throws RestAPIException, AutoscalerServiceInvalidPolicyExceptionException, AutoscalerServiceInvalidDeploymentPolicyExceptionException, AutoscalerServiceDeploymentPolicyNotExistsExceptionException {
  try {
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    int tenantId=carbonContext.getTenantId();
    NetworkPartitionBean[] networkPartitions=getNetworkPartitions();
    for (    NetworkPartitionReferenceBean networkPartitionReferenceBean : deploymentPolicyDefinitionBean.getNetworkPartitions()) {
      NetworkPartition networkPartition=CloudControllerServiceClient.getInstance().getNetworkPartitionByTenant(networkPartitionReferenceBean.getId(),tenantId);
      for (      NetworkPartitionBean networkPartitionBean : networkPartitions) {
        if (networkPartition.getTenantId() == tenantId && networkPartitionBean.getId().equals(networkPartitionReferenceBean.getId())) {
          networkPartitionReferenceBean.setUuid(networkPartition.getUuid());
          for (          PartitionReferenceBean partition : networkPartitionReferenceBean.getPartitions()) {
            for (            PartitionBean existingPartition : networkPartitionBean.getPartitions()) {
              if (existingPartition.getTenantId() == tenantId && partition.getId().equals(existingPartition.getId())) {
                partition.setUuid(existingPartition.getUuid());
                partition.setTenantId(tenantId);
              }
            }
          }
        }
      }
    }
    AutoscalerServiceClient serviceClient=AutoscalerServiceClient.getInstance();
    DeploymentPolicy deploymentPolicy=serviceClient.getDeploymentPolicyByTenant(deploymentPolicyDefinitionBean.getId(),carbonContext.getTenantId());
    if (log.isDebugEnabled()) {
      log.debug(String.format("String_Node_Str" + "String_Node_Str",deploymentPolicy.getUuid(),deploymentPolicyDefinitionBean.getId()));
    }
    AutoscalerServiceClient.getInstance().updateDeploymentPolicy(ObjectConverter.convertDeploymentPolicyBeanToASDeploymentPolicy(deploymentPolicyDefinitionBean,deploymentPolicy.getUuid(),carbonContext.getTenantId()));
    if (log.isDebugEnabled()) {
      log.debug(String.format("String_Node_Str" + "String_Node_Str",deploymentPolicy.getUuid(),deploymentPolicyDefinitionBean.getId()));
    }
  }
 catch (  RemoteException e) {
    String msg="String_Node_Str" + e.getLocalizedMessage();
    log.error(msg,e);
    throw new RestAPIException(msg);
  }
catch (  AutoscalerServiceCloudControllerConnectionExceptionException e) {
    String msg="String_Node_Str" + e.getLocalizedMessage();
    log.error(msg,e);
    throw new RestAPIException(msg);
  }
catch (  AutoscalerServiceRemoteExceptionException e) {
    String msg="String_Node_Str" + e.getLocalizedMessage();
    log.error(msg,e);
    throw new RestAPIException(msg);
  }
}

Fixed version (ground truth):
/** 
 * Update deployment policy
 * @param deploymentPolicyDefinitionBean DeploymentPolicyBean
 * @throws RestAPIException
 */
public static void updateDeploymentPolicy(DeploymentPolicyBean deploymentPolicyDefinitionBean) throws RestAPIException, AutoscalerServiceInvalidPolicyExceptionException, AutoscalerServiceInvalidDeploymentPolicyExceptionException, AutoscalerServiceDeploymentPolicyNotExistsExceptionException {
  try {
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    int tenantId=carbonContext.getTenantId();
    NetworkPartitionBean[] networkPartitions=getNetworkPartitions();
    for (    NetworkPartitionReferenceBean networkPartitionReferenceBean : deploymentPolicyDefinitionBean.getNetworkPartitions()) {
      NetworkPartition networkPartition=CloudControllerServiceClient.getInstance().getNetworkPartitionByTenant(networkPartitionReferenceBean.getId(),tenantId);
      if (networkPartition == null) {
        String message=String.format("String_Node_Str" + "String_Node_Str",deploymentPolicyDefinitionBean.getId(),networkPartitionReferenceBean.getId());
        throw new RestAPIException(message);
      }
      for (      NetworkPartitionBean networkPartitionBean : networkPartitions) {
        if (networkPartition.getTenantId() == tenantId && networkPartitionBean.getId().equals(networkPartitionReferenceBean.getId())) {
          networkPartitionReferenceBean.setUuid(networkPartition.getUuid());
          for (          PartitionReferenceBean partition : networkPartitionReferenceBean.getPartitions()) {
            for (            PartitionBean existingPartition : networkPartitionBean.getPartitions()) {
              if (existingPartition.getTenantId() == tenantId && partition.getId().equals(existingPartition.getId())) {
                partition.setUuid(existingPartition.getUuid());
                partition.setTenantId(tenantId);
              }
            }
          }
        }
      }
    }
    AutoscalerServiceClient serviceClient=AutoscalerServiceClient.getInstance();
    DeploymentPolicy deploymentPolicy=serviceClient.getDeploymentPolicyByTenant(deploymentPolicyDefinitionBean.getId(),carbonContext.getTenantId());
    if (log.isDebugEnabled()) {
      log.debug(String.format("String_Node_Str" + "String_Node_Str",deploymentPolicy.getUuid(),deploymentPolicyDefinitionBean.getId()));
    }
    AutoscalerServiceClient.getInstance().updateDeploymentPolicy(ObjectConverter.convertDeploymentPolicyBeanToASDeploymentPolicy(deploymentPolicyDefinitionBean,deploymentPolicy.getUuid(),carbonContext.getTenantId()));
    if (log.isDebugEnabled()) {
      log.debug(String.format("String_Node_Str" + "String_Node_Str",deploymentPolicy.getUuid(),deploymentPolicyDefinitionBean.getId()));
    }
  }
 catch (  RemoteException e) {
    String msg="String_Node_Str" + e.getLocalizedMessage();
    log.error(msg,e);
    throw new RestAPIException(msg);
  }
catch (  AutoscalerServiceCloudControllerConnectionExceptionException e) {
    String msg="String_Node_Str" + e.getLocalizedMessage();
    log.error(msg,e);
    throw new RestAPIException(msg);
  }
catch (  AutoscalerServiceRemoteExceptionException e) {
    String msg="String_Node_Str" + e.getLocalizedMessage();
    log.error(msg,e);
    throw new RestAPIException(msg);
  }
}