Program: 115940
Project: 115940
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 TODO
 * @return the partition context
 */
private void addPartitionContext(Instance parentInstanceContext,GroupLevelNetworkPartitionContext networkPartitionContext,String groupAlias){
  String networkPartitionId=parentInstanceContext.getNetworkPartitionId();
  List<GroupLevelPartitionContext> childPartitionContexts=new ArrayList<GroupLevelPartitionContext>();
  String deploymentPolicyId=AutoscalerUtil.getDeploymentPolicyIdByAlias(appId,groupAlias);
  DeploymentPolicy deploymentPolicy=null;
  try {
    deploymentPolicy=CloudControllerServiceClient.getInstance().getDeploymentPolicy(deploymentPolicyId);
  }
 catch (  Exception e) {
    String msg=String.format("String_Node_Str" + "String_Node_Str",this.appId,groupAlias);
    log.error(msg,e);
    return;
  }
  NetworkPartitionRef[] networkPartitionRefs=deploymentPolicy.getNetworkPartitionsRef();
  NetworkPartitionRef networkPartitionRef=null;
  if (networkPartitionRefs != null && networkPartitionRefs.length != 0) {
    for (    NetworkPartitionRef i : networkPartitionRefs) {
      if (i.getId().equals(networkPartitionId)) {
        networkPartitionRef=i;
      }
    }
  }
  if (networkPartitionRef != null) {
    if (networkPartitionContext.getPartitionCtxts().isEmpty()) {
      PartitionRef[] partitionRefs=networkPartitionRef.getPartitions();
      if (partitionRefs != null && partitionRefs.length != 0) {
        for (        PartitionRef partitionRef : partitionRefs) {
          if (networkPartitionContext.getPartitionCtxt(partitionRef.getId()) == null) {
            GroupLevelPartitionContext groupLevelPartitionContext=new GroupLevelPartitionContext(partitionRef.getMax(),partitionRef.getId(),networkPartitionId);
            childPartitionContexts.add(groupLevelPartitionContext);
            networkPartitionContext.addPartitionContext(groupLevelPartitionContext);
            if (log.isInfoEnabled()) {
              log.info(String.format("String_Node_Str",partitionRef.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 TODO
 * @return the partition context
 */
private void addPartitionContext(Instance parentInstanceContext,GroupLevelNetworkPartitionContext networkPartitionContext,String groupAlias){
  String networkPartitionId=parentInstanceContext.getNetworkPartitionId();
  List<GroupLevelPartitionContext> childPartitionContexts=new ArrayList<GroupLevelPartitionContext>();
  String deploymentPolicyId=AutoscalerUtil.getDeploymentPolicyIdByAlias(appId,groupAlias);
  DeploymentPolicy deploymentPolicy=null;
  try {
    deploymentPolicy=CloudControllerServiceClient.getInstance().getDeploymentPolicy(deploymentPolicyId);
  }
 catch (  CloudControllerServiceDeploymentPolicyNotExistsExceptionException e) {
    String msg=String.format("String_Node_Str",deploymentPolicyId);
    log.warn(msg);
  }
catch (  Exception e) {
    String msg=String.format("String_Node_Str",deploymentPolicyId,e);
    log.error(msg,e);
    throw new org.apache.stratos.autoscaler.exception.AutoScalerException(msg,e);
  }
  if (deploymentPolicy == null) {
    String parentPartitionId=parentInstanceContext.getPartitionId();
    if (parentPartitionId != null && networkPartitionContext.getPartitionCtxt(parentPartitionId) == null) {
      GroupLevelPartitionContext partitionContext=new GroupLevelPartitionContext(parentPartitionId,networkPartitionId);
      networkPartitionContext.addPartitionContext((GroupLevelPartitionContext)partitionContext);
      if (log.isInfoEnabled()) {
        log.info("String_Node_Str" + parentPartitionId + "String_Node_Str"+ "String_Node_Str"+ this.id);
      }
    }
  }
 else {
    NetworkPartitionRef[] networkPartitionRefs=deploymentPolicy.getNetworkPartitionsRef();
    NetworkPartitionRef networkPartitionRef=null;
    if (networkPartitionRefs != null && networkPartitionRefs.length != 0) {
      for (      NetworkPartitionRef i : networkPartitionRefs) {
        if (i.getId().equals(networkPartitionId)) {
          networkPartitionRef=i;
        }
      }
    }
    if (networkPartitionRef != null) {
      if (networkPartitionContext.getPartitionCtxts().isEmpty()) {
        PartitionRef[] partitionRefs=networkPartitionRef.getPartitions();
        if (partitionRefs != null && partitionRefs.length != 0) {
          for (          PartitionRef partitionRef : partitionRefs) {
            if (networkPartitionContext.getPartitionCtxt(partitionRef.getId()) == null) {
              GroupLevelPartitionContext groupLevelPartitionContext=new GroupLevelPartitionContext(partitionRef.getMax(),partitionRef.getId(),networkPartitionId);
              childPartitionContexts.add(groupLevelPartitionContext);
              networkPartitionContext.addPartitionContext(groupLevelPartitionContext);
              if (log.isInfoEnabled()) {
                log.info(String.format("String_Node_Str",partitionRef.getId(),this.id));
              }
            }
          }
        }
      }
    }
  }
}