Program: 115487
Project: 115487
Buggy source:
/** 
 * Add an application policy
 * @param applicationPolicyBean applicationPolicyBean
 * @throws RestAPIException
 */
public static void addApplicationPolicy(ApplicationPolicyBean applicationPolicyBean,String applicationPolicyUuid,int tenantId) throws RestAPIException, AutoscalerServiceInvalidApplicationPolicyExceptionException, AutoscalerServiceApplicationPolicyAlreadyExistsExceptionException {
  if (applicationPolicyBean == null) {
    String msg="String_Node_Str";
    log.error(msg);
    throw new ApplicationPolicyIsEmptyException(msg);
  }
  CloudControllerServiceClient cloudServiceClient=getCloudControllerServiceClient();
  AutoscalerServiceClient serviceClient=getAutoscalerServiceClient();
  try {
    ApplicationPolicy applicationPolicy=ObjectConverter.convertApplicationPolicyBeanToStubAppPolicy(applicationPolicyBean,applicationPolicyUuid,tenantId);
    if (applicationPolicy == null) {
      String msg="String_Node_Str";
      log.error(msg);
      throw new ApplicationPolicyIsEmptyException(msg);
    }
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    NetworkPartition[] existingNetworkPartitions=cloudServiceClient.getNetworkPartitionsByTenant(carbonContext.getTenantId());
    String[] networkPartitions=applicationPolicy.getNetworkPartitions();
    String[] networkPartitionsUuid=new String[applicationPolicy.getNetworkPartitions().length];
    for (int i=0; i < networkPartitions.length; i++) {
      for (      NetworkPartition networkPartition : existingNetworkPartitions) {
        if (networkPartitions[i].equals(networkPartition.getId()) && (tenantId == networkPartition.getTenantId())) {
          networkPartitionsUuid[i]=networkPartition.getUuid();
        }
      }
    }
    applicationPolicy.setNetworkPartitionsUuid(networkPartitionsUuid);
    serviceClient.addApplicationPolicy(applicationPolicy);
  }
 catch (  RemoteException 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):
/** 
 * Add an application policy
 * @param applicationPolicyBean applicationPolicyBean
 * @throws RestAPIException
 */
public static void addApplicationPolicy(ApplicationPolicyBean applicationPolicyBean,String applicationPolicyUuid,int tenantId) throws RestAPIException, AutoscalerServiceInvalidApplicationPolicyExceptionException, AutoscalerServiceApplicationPolicyAlreadyExistsExceptionException {
  if (applicationPolicyBean == null) {
    String msg="String_Node_Str";
    log.error(msg);
    throw new ApplicationPolicyIsEmptyException(msg);
  }
  CloudControllerServiceClient cloudServiceClient=getCloudControllerServiceClient();
  AutoscalerServiceClient serviceClient=getAutoscalerServiceClient();
  try {
    ApplicationPolicy applicationPolicy=ObjectConverter.convertApplicationPolicyBeanToStubAppPolicy(applicationPolicyBean,applicationPolicyUuid,tenantId);
    if (applicationPolicy == null) {
      String msg="String_Node_Str";
      log.error(msg);
      throw new ApplicationPolicyIsEmptyException(msg);
    }
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    NetworkPartition[] existingNetworkPartitions=cloudServiceClient.getNetworkPartitionsByTenant(carbonContext.getTenantId());
    String[] networkPartitions=applicationPolicy.getNetworkPartitions();
    String[] networkPartitionsUuid=new String[applicationPolicy.getNetworkPartitions().length];
    for (int i=0; i < networkPartitions.length; i++) {
      if (existingNetworkPartitions != null) {
        for (        NetworkPartition networkPartition : existingNetworkPartitions) {
          if (networkPartitions[i].equals(networkPartition.getId()) && (tenantId == networkPartition.getTenantId())) {
            networkPartitionsUuid[i]=networkPartition.getUuid();
          }
        }
      }
 else {
        String message=String.format("String_Node_Str" + "String_Node_Str",applicationPolicyBean.getId(),networkPartitions[i]);
        throw new RestAPIException(message);
      }
    }
    applicationPolicy.setNetworkPartitionsUuid(networkPartitionsUuid);
    serviceClient.addApplicationPolicy(applicationPolicy);
  }
 catch (  RemoteException 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);
  }
}