Program: 115488
Project: 115488
Buggy source:
/** 
 * Validates Application Policy against the given application.
 * @param applicationPolicy the application policy to be validated
 * @throws InvalidApplicationPolicyException if application policy is not valid
 * @throws RemoteException                   is anything went wrong while communicating with CC to validate network partitions
 */
public static void validateApplicationPolicy(ApplicationPolicy applicationPolicy) throws InvalidApplicationPolicyException, RemoteException {
  if (null == applicationPolicy) {
    String msg="String_Node_Str";
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  if (applicationPolicy.getUuid() == null || StringUtils.isBlank(applicationPolicy.getUuid())) {
    String msg="String_Node_Str";
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  String algorithm=applicationPolicy.getAlgorithm();
  if (algorithm == null || StringUtils.isBlank(algorithm)) {
    String msg="String_Node_Str" + "String_Node_Str";
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  if (!algorithm.equals(StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID) && !algorithm.equals(StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID)) {
    String msg=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID,StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID,algorithm);
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  String[] networkPartitionIds=applicationPolicy.getNetworkPartitionsUuid();
  if (null == networkPartitionIds || networkPartitionIds.length == 0) {
    String msg="String_Node_Str" + "String_Node_Str";
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  for (  String networkPartitionId : networkPartitionIds) {
    if (null == networkPartitionId || networkPartitionId.isEmpty()) {
      String msg=String.format("String_Node_Str" + "String_Node_Str",networkPartitionId);
      log.error(msg);
      throw new InvalidApplicationPolicyException(msg);
    }
    NetworkPartition[] networkPartitions=CloudControllerServiceClient.getInstance().getNetworkPartitions();
    NetworkPartition networkPartitionForTenant=null;
    if (networkPartitions != null) {
      for (      NetworkPartition networkPartition : networkPartitions) {
        if (applicationPolicy.getTenantId() == networkPartition.getTenantId() && networkPartition.getUuid().equals(networkPartitionId)) {
          networkPartitionForTenant=networkPartition;
        }
      }
    }
    if (networkPartitionForTenant == null) {
      String msg=String.format("String_Node_Str" + "String_Node_Str",networkPartitionId,applicationPolicy.getUuid(),applicationPolicy.getId());
      log.error(msg);
      throw new InvalidApplicationPolicyException(msg);
    }
  }
  Properties properties=applicationPolicy.getProperties();
  if (properties != null) {
    Property networkPartitionGroupsProperty=properties.getProperty(StratosConstants.APPLICATION_POLICY_NETWORK_PARTITION_GROUPS);
    if (networkPartitionGroupsProperty != null) {
      String networkPartitionGroupsPropertyValue=networkPartitionGroupsProperty.getValue();
      if (networkPartitionGroupsPropertyValue != null) {
        String[] networkPartitionGroups=networkPartitionGroupsPropertyValue.split(StratosConstants.APPLICATION_POLICY_NETWORK_PARTITION_GROUPS_SPLITTER);
        String[] networkPartitionGroupsUuid=null;
        if (networkPartitionGroups != null) {
          int i=0;
          for (          String networkPartitionIdsString : networkPartitionGroups) {
            networkPartitionIds=networkPartitionIdsString.split(StratosConstants.APPLICATION_POLICY_NETWORK_PARTITIONS_SPLITTER);
            if (networkPartitionIds != null) {
              networkPartitionGroupsUuid=new String[networkPartitionGroups.length];
              for (              String networkPartitionId : networkPartitionIds) {
                if (null == networkPartitionId || networkPartitionId.isEmpty()) {
                  String msg=String.format("String_Node_Str" + "String_Node_Str",networkPartitionId);
                  log.error(msg);
                  throw new InvalidApplicationPolicyException(msg);
                }
                NetworkPartition networkPartition=CloudControllerServiceClient.getInstance().getNetworkPartitionByTenant(networkPartitionId,applicationPolicy.getTenantId());
                if (null == networkPartition) {
                  String msg=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",networkPartitionId);
                  log.error(msg);
                  throw new InvalidApplicationPolicyException(msg);
                }
 else {
                  networkPartitionGroupsUuid[i]=networkPartition.getUuid();
                }
              }
            }
          }
          applicationPolicy.setNetworkPartitionGroups(networkPartitionGroupsUuid);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Validates Application Policy against the given application.
 * @param applicationPolicy the application policy to be validated
 * @throws InvalidApplicationPolicyException if application policy is not valid
 * @throws RemoteException                   is anything went wrong while communicating with CC to validate network partitions
 */
public static void validateApplicationPolicy(ApplicationPolicy applicationPolicy) throws InvalidApplicationPolicyException, RemoteException {
  if (null == applicationPolicy) {
    String msg="String_Node_Str";
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  if (applicationPolicy.getUuid() == null || StringUtils.isBlank(applicationPolicy.getUuid())) {
    String msg="String_Node_Str";
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  String algorithm=applicationPolicy.getAlgorithm();
  if (algorithm == null || StringUtils.isBlank(algorithm)) {
    String msg="String_Node_Str" + "String_Node_Str";
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  if (!algorithm.equals(StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID) && !algorithm.equals(StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID)) {
    String msg=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID,StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID,algorithm);
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  String[] networkPartitionIds=applicationPolicy.getNetworkPartitions();
  if (null == networkPartitionIds || networkPartitionIds.length == 0) {
    String msg="String_Node_Str" + "String_Node_Str";
    log.error(msg);
    throw new InvalidApplicationPolicyException(msg);
  }
  for (  String networkPartitionId : networkPartitionIds) {
    if (null == networkPartitionId || networkPartitionId.isEmpty()) {
      String msg=String.format("String_Node_Str" + "String_Node_Str",networkPartitionId);
      log.error(msg);
      throw new InvalidApplicationPolicyException(msg);
    }
    NetworkPartition[] networkPartitions=CloudControllerServiceClient.getInstance().getNetworkPartitions();
    NetworkPartition networkPartitionForTenant=null;
    if (networkPartitions != null) {
      for (      NetworkPartition networkPartition : networkPartitions) {
        if (applicationPolicy.getTenantId() == networkPartition.getTenantId() && networkPartition.getId().equals(networkPartitionId)) {
          networkPartitionForTenant=networkPartition;
        }
      }
    }
    if (networkPartitionForTenant == null) {
      String msg=String.format("String_Node_Str" + "String_Node_Str",networkPartitionId,applicationPolicy.getUuid(),applicationPolicy.getId());
      log.error(msg);
      throw new InvalidApplicationPolicyException(msg);
    }
  }
  Properties properties=applicationPolicy.getProperties();
  if (properties != null) {
    Property networkPartitionGroupsProperty=properties.getProperty(StratosConstants.APPLICATION_POLICY_NETWORK_PARTITION_GROUPS);
    if (networkPartitionGroupsProperty != null) {
      String networkPartitionGroupsPropertyValue=networkPartitionGroupsProperty.getValue();
      if (networkPartitionGroupsPropertyValue != null) {
        String[] networkPartitionGroups=networkPartitionGroupsPropertyValue.split(StratosConstants.APPLICATION_POLICY_NETWORK_PARTITION_GROUPS_SPLITTER);
        String[] networkPartitionGroupsUuid=null;
        if (networkPartitionGroups != null) {
          int i=0;
          for (          String networkPartitionIdsString : networkPartitionGroups) {
            networkPartitionIds=networkPartitionIdsString.split(StratosConstants.APPLICATION_POLICY_NETWORK_PARTITIONS_SPLITTER);
            if (networkPartitionIds != null) {
              networkPartitionGroupsUuid=new String[networkPartitionGroups.length];
              for (              String networkPartitionId : networkPartitionIds) {
                if (null == networkPartitionId || networkPartitionId.isEmpty()) {
                  String msg=String.format("String_Node_Str" + "String_Node_Str",networkPartitionId);
                  log.error(msg);
                  throw new InvalidApplicationPolicyException(msg);
                }
                NetworkPartition networkPartition=CloudControllerServiceClient.getInstance().getNetworkPartitionByTenant(networkPartitionId,applicationPolicy.getTenantId());
                if (null == networkPartition) {
                  String msg=String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",networkPartitionId);
                  log.error(msg);
                  throw new InvalidApplicationPolicyException(msg);
                }
 else {
                  networkPartitionGroupsUuid[i]=networkPartition.getUuid();
                }
              }
            }
          }
          applicationPolicy.setNetworkPartitionGroups(networkPartitionGroupsUuid);
        }
      }
    }
  }
}