Program: 115532
Project: 115532
Buggy source:
/** 
 * Remove Network Partition
 * @param networkPartitionId networkPartitionId
 */
public static void removeNetworkPartition(String networkPartitionId,int tenantId) throws RestAPIException, CloudControllerServiceNetworkPartitionNotExistsExceptionException {
  try {
    AutoscalerServiceClient autoscalerServiceClient=AutoscalerServiceClient.getInstance();
    ApplicationContext[] applicationContexts=autoscalerServiceClient.getApplicationsByTenant(tenantId);
    if (applicationContexts != null) {
      for (      ApplicationContext applicationContext : applicationContexts) {
        if (applicationContext != null) {
          String[] networkPartitions=AutoscalerServiceClient.getInstance().getApplicationNetworkPartitions(applicationContext.getApplicationUuid());
          if (networkPartitions != null) {
            for (int i=0; i < networkPartitions.length; i++) {
              if (networkPartitions[i].equals(networkPartitionId)) {
                String message=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",networkPartitionId,applicationContext.getApplicationUuid(),applicationContext.getApplicationId());
                log.error(message);
                throw new RestAPIException(message);
              }
            }
          }
        }
      }
    }
    String networkPartitionUuid=null;
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    for (    NetworkPartitionBean networkPartitionBean : getNetworkPartitions()) {
      if (networkPartitionBean.getTenantId() == carbonContext.getTenantId() && networkPartitionBean.getId().equals(networkPartitionId)) {
        networkPartitionUuid=networkPartitionBean.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 networkPartition : applicationPolicy.getNetworkPartitionsUuid()) {
          if (networkPartition.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);
          }
        }
      }
    }
    CloudControllerServiceClient serviceClient=CloudControllerServiceClient.getInstance();
    serviceClient.removeNetworkPartition(networkPartitionId,tenantId);
  }
 catch (  AutoscalerServiceAutoScalerExceptionException 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);
    String networkPartitionUuid=null;
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    for (    NetworkPartitionBean networkPartitionBean : getNetworkPartitions()) {
      if (networkPartitionBean.getTenantId() == carbonContext.getTenantId() && networkPartitionBean.getId().equals(networkPartitionId)) {
        networkPartitionUuid=networkPartitionBean.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 networkPartition : applicationPolicy.getNetworkPartitionsUuid()) {
          if (networkPartition.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);
          }
        }
      }
    }
    CloudControllerServiceClient serviceClient=CloudControllerServiceClient.getInstance();
    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);
  }
}