Program: 115746
Project: 115746
Buggy source:
/** 
 * Finds the correct partition context to which the instance should be added to and created and adds required context objects.
 * @param parentInstanceContext   the parent instance context
 * @param networkPartitionContext the GroupLevelNetworkPartitionContext
 * @param groupAlias alias of the group
 */
private void addPartitionContext(Instance parentInstanceContext,GroupLevelNetworkPartitionContext networkPartitionContext,String groupAlias){
  String networkPartitionId=parentInstanceContext.getNetworkPartitionId();
  String deploymentPolicyId=AutoscalerUtil.getDeploymentPolicyIdByAlias(appId,groupAlias);
  DeploymentPolicy deploymentPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId);
  if (deploymentPolicy == null) {
    String parentPartitionId=parentInstanceContext.getPartitionId();
    if (parentPartitionId != null && networkPartitionContext.getPartitionCtxt(parentPartitionId) == null) {
      GroupLevelPartitionContext partitionContext=new GroupLevelPartitionContext(parentPartitionId,networkPartitionId);
      networkPartitionContext.addPartitionContext(partitionContext);
      if (log.isInfoEnabled()) {
        log.info("String_Node_Str" + parentPartitionId + "String_Node_Str"+ "String_Node_Str"+ this.id);
      }
    }
  }
 else {
    NetworkPartition[] networkPartitions=deploymentPolicy.getNetworkPartitions();
    NetworkPartition networkPartition=null;
    if (networkPartitions != null && networkPartitions.length != 0) {
      for (      NetworkPartition i : networkPartitions) {
        if (i.getId().equals(networkPartitionId)) {
          networkPartition=i;
        }
      }
    }
    if (networkPartition != null) {
      if (networkPartitionContext.getPartitionCtxts().isEmpty()) {
        Partition[] partitions=networkPartition.getPartitions();
        if (partitions != null && partitions.length != 0) {
          for (          Partition partition : partitions) {
            if (networkPartitionContext.getPartitionCtxt(partition.getId()) == null) {
              GroupLevelPartitionContext groupLevelPartitionContext=new GroupLevelPartitionContext(partition.getId(),networkPartitionId,deploymentPolicyId);
              networkPartitionContext.addPartitionContext(groupLevelPartitionContext);
              if (log.isInfoEnabled()) {
                log.info(String.format("String_Node_Str",partition.getId(),this.id));
              }
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Finds the correct partition context to which the instance should be added to and created and adds required context objects.
 * @param parentInstanceContext   the parent instance context
 * @param networkPartitionContext the GroupLevelNetworkPartitionContext
 * @param groupAlias              alias of the group
 */
private void addPartitionContext(Instance parentInstanceContext,GroupLevelNetworkPartitionContext networkPartitionContext,String groupAlias){
  String networkPartitionId=parentInstanceContext.getNetworkPartitionId();
  String deploymentPolicyId=AutoscalerUtil.getDeploymentPolicyIdByAlias(appId,groupAlias);
  DeploymentPolicy deploymentPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId);
  if (deploymentPolicy == null) {
    String parentPartitionId=parentInstanceContext.getPartitionId();
    if (parentPartitionId != null && networkPartitionContext.getPartitionCtxt(parentPartitionId) == null) {
      GroupLevelPartitionContext partitionContext=new GroupLevelPartitionContext(parentPartitionId,networkPartitionId);
      networkPartitionContext.addPartitionContext(partitionContext);
      if (log.isInfoEnabled()) {
        log.info("String_Node_Str" + parentPartitionId + "String_Node_Str"+ "String_Node_Str"+ this.id);
      }
    }
  }
 else {
    NetworkPartition[] networkPartitions=deploymentPolicy.getNetworkPartitions();
    NetworkPartition networkPartition=null;
    if (networkPartitions != null && networkPartitions.length != 0) {
      for (      NetworkPartition i : networkPartitions) {
        if (i.getId().equals(networkPartitionId)) {
          networkPartition=i;
        }
      }
    }
    if (networkPartition != null) {
      if (networkPartitionContext.getPartitionCtxts().isEmpty()) {
        Partition[] partitions=networkPartition.getPartitions();
        if (partitions != null && partitions.length != 0) {
          for (          Partition partition : partitions) {
            if (networkPartitionContext.getPartitionCtxt(partition.getId()) == null) {
              GroupLevelPartitionContext groupLevelPartitionContext=new GroupLevelPartitionContext(partition.getId(),networkPartitionId,deploymentPolicyId);
              networkPartitionContext.addPartitionContext(groupLevelPartitionContext);
              if (log.isInfoEnabled()) {
                log.info(String.format("String_Node_Str",partition.getId(),this.id));
              }
            }
          }
        }
      }
    }
  }
}