Program: 115617
Project: 115617
Buggy source:
/** 
 * This will start the group instance based on the given parent instanceId A new monitor is not created in this case
 * @param parentInstanceId the parent instance id
 */
public boolean createInstanceOnDemand(String parentInstanceId){
  Instance parentInstanceContext=getParentInstanceContext(parentInstanceId);
  List<String> instanceIdsToStart=new ArrayList<String>();
  Group group=ApplicationHolder.getApplications().getApplication(this.appId).getGroupRecursively(this.id);
  ParentLevelNetworkPartitionContext parentLevelNetworkPartitionContext=getGroupLevelNetworkPartitionContext(group.getUniqueIdentifier(),this.appId,parentInstanceContext);
  addPartitionContext(parentInstanceContext,parentLevelNetworkPartitionContext,group.getAlias());
  String groupInstanceId;
  PartitionContext partitionContext;
  String parentPartitionId=parentInstanceContext.getPartitionId();
  int groupMax=group.getGroupMaxInstances();
  int groupMin=group.getGroupMinInstances();
  List<Instance> instances=group.getInstanceContextsWithParentId(parentInstanceId);
  if (instances.isEmpty()) {
    for (int i=0; i < groupMin; i++) {
      partitionContext=getPartitionContext(parentLevelNetworkPartitionContext,parentPartitionId);
      groupInstanceId=createGroupInstanceAndAddToMonitor(group,parentInstanceContext,partitionContext,parentLevelNetworkPartitionContext,null);
      instanceIdsToStart.add(groupInstanceId);
    }
  }
 else {
    if (parentLevelNetworkPartitionContext.getNonTerminatedInstancesCount(parentInstanceId) < groupMax) {
      String deploymentPolicyId=AutoscalerUtil.getDeploymentPolicyIdByAlias(appId,id);
      if (deploymentPolicyId != null) {
        partitionContext=getPartitionContext(parentLevelNetworkPartitionContext,parentPartitionId);
        if (partitionContext != null) {
          groupInstanceId=createGroupInstanceAndAddToMonitor(group,parentInstanceContext,partitionContext,parentLevelNetworkPartitionContext,null);
          instanceIdsToStart.add(groupInstanceId);
        }
 else {
          log.warn("String_Node_Str" + "String_Node_Str" + group.getUniqueIdentifier() + "String_Node_Str"+ "String_Node_Str"+ groupMax+ "String_Node_Str");
        }
      }
 else {
        groupInstanceId=createGroupInstanceAndAddToMonitor(group,parentInstanceContext,null,parentLevelNetworkPartitionContext,null);
        instanceIdsToStart.add(groupInstanceId);
      }
    }
 else {
      log.warn("String_Node_Str" + group.getUniqueIdentifier() + "String_Node_Str"+ "String_Node_Str"+ groupMax+ "String_Node_Str");
    }
  }
  boolean startedOnDemand=false;
  if (!instanceIdsToStart.isEmpty()) {
    startedOnDemand=true;
    startDependency(group,instanceIdsToStart);
  }
  return startedOnDemand;
}

Fixed version (ground truth):
/** 
 * This will start the group instance based on the given parent instanceId A new monitor is not created in this case
 * @param parentInstanceId the parent instance id
 */
public boolean createInstanceOnDemand(String parentInstanceId){
  Instance parentInstanceContext=getParentInstanceContext(parentInstanceId);
  List<String> instanceIdsToStart=new ArrayList<String>();
  Group group=ApplicationHolder.getApplications().getApplication(this.appId).getGroupRecursively(this.id);
  log.info("String_Node_Str" + appId + "String_Node_Str"+ id+ "String_Node_Str"+ "String_Node_Str"+ parentInstanceId);
  ParentLevelNetworkPartitionContext parentLevelNetworkPartitionContext=getGroupLevelNetworkPartitionContext(group.getUniqueIdentifier(),this.appId,parentInstanceContext);
  addPartitionContext(parentInstanceContext,parentLevelNetworkPartitionContext,group.getAlias());
  String groupInstanceId;
  PartitionContext partitionContext;
  String parentPartitionId=parentInstanceContext.getPartitionId();
  int groupMax=group.getGroupMaxInstances();
  int groupMin=group.getGroupMinInstances();
  List<Instance> instances=group.getInstanceContextsWithParentId(parentInstanceId);
  if (instances.isEmpty()) {
    for (int i=0; i < groupMin; i++) {
      partitionContext=getPartitionContext(parentLevelNetworkPartitionContext,parentPartitionId);
      groupInstanceId=createGroupInstanceAndAddToMonitor(group,parentInstanceContext,partitionContext,parentLevelNetworkPartitionContext,null);
      instanceIdsToStart.add(groupInstanceId);
    }
  }
 else {
    if (parentLevelNetworkPartitionContext.getNonTerminatedInstancesCount(parentInstanceId) < groupMax) {
      String deploymentPolicyId=AutoscalerUtil.getDeploymentPolicyIdByAlias(appId,id);
      if (deploymentPolicyId != null) {
        partitionContext=getPartitionContext(parentLevelNetworkPartitionContext,parentPartitionId);
        if (partitionContext != null) {
          groupInstanceId=createGroupInstanceAndAddToMonitor(group,parentInstanceContext,partitionContext,parentLevelNetworkPartitionContext,null);
          instanceIdsToStart.add(groupInstanceId);
        }
 else {
          log.warn("String_Node_Str" + "String_Node_Str" + group.getUniqueIdentifier() + "String_Node_Str"+ "String_Node_Str"+ groupMax+ "String_Node_Str");
        }
      }
 else {
        groupInstanceId=createGroupInstanceAndAddToMonitor(group,parentInstanceContext,null,parentLevelNetworkPartitionContext,null);
        instanceIdsToStart.add(groupInstanceId);
      }
    }
 else {
      log.warn("String_Node_Str" + group.getUniqueIdentifier() + "String_Node_Str"+ "String_Node_Str"+ groupMax+ "String_Node_Str");
    }
  }
  boolean startedOnDemand=false;
  if (!instanceIdsToStart.isEmpty()) {
    startedOnDemand=true;
    startDependency(group,instanceIdsToStart);
  }
  return startedOnDemand;
}