Program: 115486
Project: 115486
Buggy source:
/** 
 * Remove Network Partition
 * @param networkPartitionId networkPartitionId
 */
public static void removeNetworkPartition(String networkPartitionId,int tenantId) throws RestAPIException, CloudControllerServiceNetworkPartitionNotExistsExceptionException {
  try {
    AutoscalerServiceClient autoscalerServiceClient=AutoscalerServiceClient.getInstance();
    autoscalerServiceClient.validateNetworkPartitionWithApplication(networkPartitionId,tenantId);
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    CloudControllerServiceClient serviceClient=CloudControllerServiceClient.getInstance();
    org.apache.stratos.cloud.controller.stub.domain.NetworkPartition networkPartition=serviceClient.getNetworkPartitionByTenant(networkPartitionId,tenantId);
    String networkPartitionUuid=networkPartition.getUuid();
    DeploymentPolicy[] deploymentPolicies=autoscalerServiceClient.getDeploymentPoliciesByTenant(carbonContext.getTenantId());
    if (deploymentPolicies != null) {
      for (      DeploymentPolicy deploymentPolicy : deploymentPolicies) {
        for (        org.apache.stratos.autoscaler.stub.partition.NetworkPartitionRef networkPartitionRef : deploymentPolicy.getNetworkPartitionRefs()) {
          if (networkPartitionRef.getUuid().equals(networkPartitionUuid)) {
            String message=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",networkPartitionUuid,networkPartitionId,deploymentPolicy.getUuid(),deploymentPolicy.getId());
            log.error(message);
            throw new RestAPIException(message);
          }
        }
      }
    }
    ApplicationPolicy[] applicationPolicies=autoscalerServiceClient.getApplicationPolicies();
    if (applicationPolicies != null) {
      for (      ApplicationPolicy applicationPolicy : applicationPolicies) {
        for (        String networkPartitionUuid1 : applicationPolicy.getNetworkPartitionsUuid()) {
          if (networkPartitionUuid1.equals(networkPartitionUuid)) {
            String message=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",networkPartitionUuid,networkPartitionId,applicationPolicy.getUuid(),applicationPolicy.getId());
            log.error(message);
            throw new RestAPIException(message);
          }
        }
      }
    }
    serviceClient.removeNetworkPartition(networkPartitionId,tenantId);
  }
 catch (  AutoscalerServicePartitionValidationExceptionException e) {
    String message=e.getMessage();
    log.error(message);
    throw new RestAPIException(message,e);
  }
catch (  RemoteException e) {
    String message=e.getMessage();
    log.error(message);
    throw new RestAPIException(message,e);
  }
}

Fixed version (ground truth):
/** 
 * Remove Network Partition
 * @param networkPartitionId networkPartitionId
 */
public static void removeNetworkPartition(String networkPartitionId,int tenantId) throws RestAPIException, CloudControllerServiceNetworkPartitionNotExistsExceptionException {
  try {
    AutoscalerServiceClient autoscalerServiceClient=AutoscalerServiceClient.getInstance();
    autoscalerServiceClient.validateNetworkPartitionWithApplication(networkPartitionId,tenantId);
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    CloudControllerServiceClient serviceClient=CloudControllerServiceClient.getInstance();
    org.apache.stratos.cloud.controller.stub.domain.NetworkPartition networkPartition=serviceClient.getNetworkPartitionByTenant(networkPartitionId,tenantId);
    String networkPartitionUuid;
    if (networkPartition != null) {
      networkPartitionUuid=networkPartition.getUuid();
    }
 else {
      String message=String.format("String_Node_Str",networkPartitionId);
      log.error(message);
      throw new RestAPIException(message);
    }
    DeploymentPolicy[] deploymentPolicies=autoscalerServiceClient.getDeploymentPoliciesByTenant(carbonContext.getTenantId());
    if (deploymentPolicies != null) {
      for (      DeploymentPolicy deploymentPolicy : deploymentPolicies) {
        for (        org.apache.stratos.autoscaler.stub.partition.NetworkPartitionRef networkPartitionRef : deploymentPolicy.getNetworkPartitionRefs()) {
          if (networkPartitionRef.getUuid().equals(networkPartitionUuid)) {
            String message=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",networkPartitionUuid,networkPartitionId,deploymentPolicy.getUuid(),deploymentPolicy.getId());
            log.error(message);
            throw new RestAPIException(message);
          }
        }
      }
    }
    ApplicationPolicy[] applicationPolicies=autoscalerServiceClient.getApplicationPolicies();
    if (applicationPolicies != null) {
      for (      ApplicationPolicy applicationPolicy : applicationPolicies) {
        for (        String networkPartitionUuid1 : applicationPolicy.getNetworkPartitionsUuid()) {
          if (networkPartitionUuid1.equals(networkPartitionUuid)) {
            String message=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",networkPartitionUuid,networkPartitionId,applicationPolicy.getUuid(),applicationPolicy.getId());
            log.error(message);
            throw new RestAPIException(message);
          }
        }
      }
    }
    serviceClient.removeNetworkPartition(networkPartitionId,tenantId);
  }
 catch (  AutoscalerServicePartitionValidationExceptionException e) {
    String message=e.getMessage();
    log.error(message);
    throw new RestAPIException(message,e);
  }
catch (  RemoteException e) {
    String message=e.getMessage();
    log.error(message);
    throw new RestAPIException(message,e);
  }
}