Program: 116156
Project: 116156
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
 * @return the partition context
 */
private void addPartitionContext(Instance parentInstanceContext,GroupLevelNetworkPartitionContext networkPartitionContext){
  String networkPartitionId=parentInstanceContext.getNetworkPartitionId();
  List<GroupLevelPartitionContext> childPartitionContexts;
  ChildPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(this.appId).getChildPolicy(this.id);
  PartitionContext partitionContext;
  String parentPartitionId=parentInstanceContext.getPartitionId();
  if (policy == null) {
    if (parentPartitionId != null && networkPartitionContext.getPartitionCtxt(parentPartitionId) != null) {
      partitionContext=new GroupLevelPartitionContext(0);
      networkPartitionContext.addPartitionContext((GroupLevelPartitionContext)partitionContext);
      if (log.isInfoEnabled()) {
        log.info("String_Node_Str" + parentPartitionId + "String_Node_Str"+ "String_Node_Str"+ this.id);
      }
    }
  }
 else {
    ChildLevelNetworkPartition networkPartition=policy.getChildLevelNetworkPartition(networkPartitionId);
    if (networkPartitionContext.getPartitionCtxts().isEmpty()) {
      ChildLevelPartition[] childLevelPartitions=networkPartition.getChildLevelPartitions();
      childPartitionContexts=new ArrayList<GroupLevelPartitionContext>();
      for (      ChildLevelPartition childLevelPartition : childLevelPartitions) {
        partitionContext=new GroupLevelPartitionContext(childLevelPartition.getMax(),childLevelPartition.getPartitionId(),networkPartitionId);
        childPartitionContexts.add((GroupLevelPartitionContext)partitionContext);
        networkPartitionContext.addPartitionContext((GroupLevelPartitionContext)partitionContext);
        if (log.isInfoEnabled()) {
          log.info("String_Node_Str" + childLevelPartition.getPartitionId() + "String_Node_Str"+ 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
 * @return the partition context
 */
private void addPartitionContext(Instance parentInstanceContext,GroupLevelNetworkPartitionContext networkPartitionContext){
  String networkPartitionId=parentInstanceContext.getNetworkPartitionId();
  List<GroupLevelPartitionContext> childPartitionContexts;
  ChildPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(this.appId).getChildPolicy(this.id);
  PartitionContext partitionContext;
  String parentPartitionId=parentInstanceContext.getPartitionId();
  if (policy == null) {
    if (parentPartitionId != null && networkPartitionContext.getPartitionCtxt(parentPartitionId) == null) {
      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 {
    ChildLevelNetworkPartition networkPartition=policy.getChildLevelNetworkPartition(networkPartitionId);
    if (networkPartitionContext.getPartitionCtxts().isEmpty()) {
      ChildLevelPartition[] childLevelPartitions=networkPartition.getChildLevelPartitions();
      childPartitionContexts=new ArrayList<GroupLevelPartitionContext>();
      for (      ChildLevelPartition childLevelPartition : childLevelPartitions) {
        partitionContext=new GroupLevelPartitionContext(childLevelPartition.getMax(),childLevelPartition.getPartitionId(),networkPartitionId);
        childPartitionContexts.add((GroupLevelPartitionContext)partitionContext);
        networkPartitionContext.addPartitionContext((GroupLevelPartitionContext)partitionContext);
        if (log.isInfoEnabled()) {
          log.info("String_Node_Str" + childLevelPartition.getPartitionId() + "String_Node_Str"+ this.id);
        }
      }
    }
  }
}