Program: 115747
Project: 115747
Buggy source:
/** 
 * This will build the dependency tree based on the given dependencies
 * @param component it will give the necessary information to build the tree
 * @return the dependency tree out of the dependency orders
 */
public DependencyTree buildDependency(ParentComponent component) throws DependencyBuilderException {
  String identifier=component.getUniqueIdentifier();
  DependencyTree dependencyTree=new DependencyTree(identifier);
  DependencyOrder dependencyOrder=component.getDependencyOrder();
  if (dependencyOrder != null) {
    log.info(String.format("String_Node_Str",identifier));
    String terminationBehaviour=dependencyOrder.getTerminationBehaviour();
    if (AutoscalerConstants.TERMINATE_NONE.equals(terminationBehaviour)) {
      dependencyTree.setTerminationBehavior(DependencyTree.TerminationBehavior.TERMINATE_NONE);
    }
 else     if (AutoscalerConstants.TERMINATE_ALL.equals(terminationBehaviour)) {
      dependencyTree.setTerminationBehavior(DependencyTree.TerminationBehavior.TERMINATE_ALL);
    }
 else     if (AutoscalerConstants.TERMINATE_DEPENDENTS.equals(terminationBehaviour)) {
      dependencyTree.setTerminationBehavior(DependencyTree.TerminationBehavior.TERMINATE_DEPENDENT);
    }
    log.info(String.format("String_Node_Str",identifier,dependencyTree.getTerminationBehavior()));
    Set<StartupOrder> startupOrders=dependencyOrder.getStartupOrders();
    ApplicationChildContext parentContext;
    if (startupOrders != null) {
      log.debug(String.format("String_Node_Str",identifier,startupOrders));
      for (      StartupOrder startupOrder : startupOrders) {
        parentContext=null;
        log.debug(String.format("String_Node_Str" + "String_Node_Str",identifier,startupOrder));
        for (        String startupOrderComponent : startupOrder.getStartupOrderComponentList()) {
          if (startupOrderComponent != null) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",identifier,startupOrder,startupOrderComponent));
            ApplicationChildContext applicationChildContext=ApplicationChildContextFactory.createApplicationChildContext(identifier,startupOrderComponent,component,dependencyTree);
            String applicationChildContextId=applicationChildContext.getId();
            ApplicationChildContext existingApplicationChildContext=dependencyTree.getApplicationChildContextByIdInPrimaryTree(applicationChildContextId);
            if (existingApplicationChildContext == null) {
              if (parentContext != null) {
                parentContext.addApplicationChildContext(applicationChildContext);
                if (log.isDebugEnabled()) {
                  log.debug(String.format("String_Node_Str" + "String_Node_Str",applicationChildContext.getId(),parentContext.getId(),dependencyTree));
                }
                parentContext=applicationChildContext;
                applicationChildContext.setParent(parentContext);
              }
 else {
                dependencyTree.addPrimaryApplicationContext(applicationChildContext);
                if (log.isDebugEnabled()) {
                  log.debug(String.format("String_Node_Str",applicationChildContext.getId(),dependencyTree));
                }
                parentContext=applicationChildContext;
              }
            }
 else {
              if (parentContext == null) {
                parentContext=existingApplicationChildContext;
                if (log.isDebugEnabled()) {
                  log.debug(String.format("String_Node_Str" + "String_Node_Str",existingApplicationChildContext.getId(),dependencyTree));
                }
              }
 else {
                ApplicationChildContext existingParentContext=dependencyTree.findParentContextWithId(applicationChildContext.getId());
                if ((existingParentContext != null) && (existingParentContext.getId().equals(existingApplicationChildContext.getId()))) {
                  if (log.isDebugEnabled()) {
                    log.debug(String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",existingParentContext.getId(),dependencyTree));
                  }
                  parentContext=existingParentContext;
                }
 else {
                  String msg="String_Node_Str" + "String_Node_Str" + startupOrder;
                  throw new DependencyBuilderException(msg);
                }
              }
            }
          }
        }
      }
    }
  }
  Collection<Group> groups=component.getAliasToGroupMap().values();
  for (  Group group : groups) {
    if (dependencyTree.getApplicationChildContextByIdInPrimaryTree(group.getAlias()) == null) {
      ApplicationChildContext context=ApplicationChildContextFactory.createGroupChildContext(group.getAlias(),dependencyTree.isTerminateDependent());
      dependencyTree.addPrimaryApplicationContext(context);
    }
  }
  Collection<ClusterDataHolder> clusterData=component.getClusterDataMap().values();
  for (  ClusterDataHolder dataHolder : clusterData) {
    if (dependencyTree.getApplicationChildContextByIdInPrimaryTree(dataHolder.getClusterId()) == null) {
      ApplicationChildContext context=ApplicationChildContextFactory.createClusterChildContext(dataHolder,dependencyTree.isTerminateDependent());
      dependencyTree.addPrimaryApplicationContext(context);
    }
  }
  if (log.isDebugEnabled()) {
    log.debug(String.format("String_Node_Str",component.getUniqueIdentifier(),dependencyTree.toString()));
  }
  return dependencyTree;
}

Fixed version (ground truth):
/** 
 * This will build the dependency tree based on the given dependencies
 * @param component it will give the necessary information to build the tree
 * @return the dependency tree out of the dependency orders
 */
public DependencyTree buildDependency(ParentComponent component) throws DependencyBuilderException {
  String identifier=component.getUniqueIdentifier();
  DependencyTree dependencyTree=new DependencyTree(identifier);
  DependencyOrder dependencyOrder=component.getDependencyOrder();
  if (dependencyOrder != null) {
    log.info(String.format("String_Node_Str",identifier));
    String terminationBehaviour=dependencyOrder.getTerminationBehaviour();
    if (AutoscalerConstants.TERMINATE_NONE.equals(terminationBehaviour)) {
      dependencyTree.setTerminationBehavior(DependencyTree.TerminationBehavior.TERMINATE_NONE);
    }
 else     if (AutoscalerConstants.TERMINATE_ALL.equals(terminationBehaviour)) {
      dependencyTree.setTerminationBehavior(DependencyTree.TerminationBehavior.TERMINATE_ALL);
    }
 else     if (AutoscalerConstants.TERMINATE_DEPENDENTS.equals(terminationBehaviour)) {
      dependencyTree.setTerminationBehavior(DependencyTree.TerminationBehavior.TERMINATE_DEPENDENT);
    }
    log.info(String.format("String_Node_Str",identifier,dependencyTree.getTerminationBehavior()));
    Set<StartupOrder> startupOrders=dependencyOrder.getStartupOrders();
    ApplicationChildContext parentContext;
    if (startupOrders != null) {
      log.debug(String.format("String_Node_Str",identifier,startupOrders));
      for (      StartupOrder startupOrder : startupOrders) {
        parentContext=null;
        log.debug(String.format("String_Node_Str" + "String_Node_Str",identifier,startupOrder));
        for (        String startupOrderComponent : startupOrder.getStartupOrderComponentList()) {
          if (startupOrderComponent != null) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",identifier,startupOrder,startupOrderComponent));
            ApplicationChildContext applicationChildContext=ApplicationChildContextFactory.createApplicationChildContext(identifier,startupOrderComponent,component,dependencyTree);
            String parentContextId=null;
            ApplicationChildContext tmpParentContext=null;
            if (parentContext != null) {
              parentContextId=parentContext.getId();
              tmpParentContext=dependencyTree.getApplicationChildContextByIdInPrimaryTree(parentContextId);
            }
            applicationChildContext.setParent(tmpParentContext);
            String applicationChildContextId=applicationChildContext.getId();
            ApplicationChildContext existingApplicationChildContext=dependencyTree.getApplicationChildContextByIdInPrimaryTree(applicationChildContextId);
            if (existingApplicationChildContext == null) {
              if (parentContext != null) {
                parentContext.addApplicationChildContext(applicationChildContext);
                if (log.isDebugEnabled()) {
                  log.debug(String.format("String_Node_Str" + "String_Node_Str",applicationChildContext.getId(),parentContext.getId(),dependencyTree));
                }
                parentContext=applicationChildContext;
              }
 else {
                dependencyTree.addPrimaryApplicationContext(applicationChildContext);
                if (log.isDebugEnabled()) {
                  log.debug(String.format("String_Node_Str",applicationChildContext.getId(),dependencyTree));
                }
                parentContext=applicationChildContext;
              }
            }
 else {
              if (parentContext == null) {
                parentContext=existingApplicationChildContext;
                if (log.isDebugEnabled()) {
                  log.debug(String.format("String_Node_Str" + "String_Node_Str",existingApplicationChildContext.getId(),dependencyTree));
                }
              }
 else {
                ApplicationChildContext existingParentContext=dependencyTree.findParentContextWithId(applicationChildContext.getId());
                if ((existingParentContext != null) && (existingParentContext.getId().equals(existingApplicationChildContext.getId()))) {
                  if (log.isDebugEnabled()) {
                    log.debug(String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",existingParentContext.getId(),dependencyTree));
                  }
                  parentContext=existingParentContext;
                }
 else {
                  String msg="String_Node_Str" + "String_Node_Str" + startupOrder;
                  throw new DependencyBuilderException(msg);
                }
              }
            }
          }
        }
      }
    }
  }
  Collection<Group> groups=component.getAliasToGroupMap().values();
  for (  Group group : groups) {
    if (dependencyTree.getApplicationChildContextByIdInPrimaryTree(group.getAlias()) == null) {
      ApplicationChildContext context=ApplicationChildContextFactory.createGroupChildContext(group.getAlias(),dependencyTree.isTerminateDependent());
      dependencyTree.addPrimaryApplicationContext(context);
    }
  }
  Collection<ClusterDataHolder> clusterData=component.getClusterDataMap().values();
  for (  ClusterDataHolder dataHolder : clusterData) {
    if (dependencyTree.getApplicationChildContextByIdInPrimaryTree(dataHolder.getClusterId()) == null) {
      ApplicationChildContext context=ApplicationChildContextFactory.createClusterChildContext(dataHolder,dependencyTree.isTerminateDependent());
      dependencyTree.addPrimaryApplicationContext(context);
    }
  }
  if (log.isDebugEnabled()) {
    log.debug(String.format("String_Node_Str",component.getUniqueIdentifier(),dependencyTree.toString()));
  }
  return dependencyTree;
}