Program: 48363
Project: 48363
Buggy source:
private void configNodes(AmClusterDef clusterDef,Map<String,String> configTypeToService,List<AmNodeDef> targetNodeDefs) throws SoftwareManagementPluginException {
  Map<Integer,List<String>> newHostsMap=new HashMap<Integer,List<String>>();
  for (  AmNodeDef targetNodeDef : targetNodeDefs) {
    int volumesCount=targetNodeDef.getVolumesCount();
    String host=targetNodeDef.getFqdn();
    if (newHostsMap.isEmpty()) {
      newHostsMap.put(volumesCount,new ArrayList<String>(Arrays.asList(host)));
    }
 else {
      List<String> newHosts=newHostsMap.get(volumesCount);
      if (newHosts != null) {
        newHosts.add(host);
        newHostsMap.put(volumesCount,newHosts);
      }
 else {
        newHostsMap.put(volumesCount,new ArrayList<String>(Arrays.asList(host)));
      }
    }
  }
  List<AmNodeGroupDef> nodeGroups=clusterDef.getNodeGroupsByNodes(targetNodeDefs);
  List<AmHostGroupInfo> amHostGroupsInfo=clusterDef.getAmHostGroupsInfoByNodeGroups(nodeGroups);
  List<String> existedConfigGroupNames=new ArrayList<String>();
  ApiConfigGroupList apiConfigGroupList=apiManager.getConfigGroupsList(clusterDef.getName());
  for (  AmHostGroupInfo amHostGroupInfo : amHostGroupsInfo) {
    for (    ApiConfigGroup group : apiConfigGroupList.getConfigGroups()) {
      logger.info("String_Node_Str" + ApiUtils.objectToJson(group));
      ApiConfigGroupInfo apiConfigGroupInfo=group.getApiConfigGroupInfo();
      if (apiConfigGroupInfo != null && apiConfigGroupInfo.getDesiredConfigs() != null) {
        List<String> newHosts=newHostsMap.get(amHostGroupInfo.getVolumesCount());
        if (amHostGroupInfo.getName().equals(apiConfigGroupInfo.getGroupName())) {
          if (newHosts != null) {
            updateConfigGroup(apiConfigGroupInfo,clusterDef.getName(),amHostGroupInfo.toApiHostGroupForClusterBlueprint(),newHosts);
            existedConfigGroupNames.add(apiConfigGroupInfo.getGroupName());
            break;
          }
        }
        if (isTheSameConfigGroup(apiConfigGroupInfo,amHostGroupInfo)) {
          apiConfigGroupInfo.setGroupName(amHostGroupInfo.getName());
          updateConfigGroup(apiConfigGroupInfo,clusterDef.getName(),amHostGroupInfo.toApiHostGroupForClusterBlueprint(),newHosts);
          existedConfigGroupNames.add(apiConfigGroupInfo.getGroupName());
        }
      }
    }
  }
  createConfigGroups(clusterDef,nodeGroups,configTypeToService,existedConfigGroupNames);
}

Fixed version (ground truth):
private void configNodes(AmClusterDef clusterDef,Map<String,String> configTypeToService,List<AmNodeDef> targetNodeDefs) throws SoftwareManagementPluginException {
  Map<Integer,List<String>> newHostsMap=new HashMap<Integer,List<String>>();
  for (  AmNodeDef targetNodeDef : targetNodeDefs) {
    int volumesCount=targetNodeDef.getVolumesCount();
    String host=targetNodeDef.getFqdn();
    if (newHostsMap.isEmpty()) {
      newHostsMap.put(volumesCount,new ArrayList<String>(Arrays.asList(host)));
    }
 else {
      List<String> newHosts=newHostsMap.get(volumesCount);
      if (newHosts != null) {
        newHosts.add(host);
        newHostsMap.put(volumesCount,newHosts);
      }
 else {
        newHostsMap.put(volumesCount,new ArrayList<String>(Arrays.asList(host)));
      }
    }
  }
  List<AmNodeGroupDef> nodeGroups=clusterDef.getNodeGroupsByNodes(targetNodeDefs);
  List<AmHostGroupInfo> amHostGroupsInfo=clusterDef.getAmHostGroupsInfoByNodeGroups(nodeGroups);
  Map<String,Set<String>> existedConfigGroupMap=new HashMap<String,Set<String>>();
  ApiConfigGroupList apiConfigGroupList=apiManager.getConfigGroupsList(clusterDef.getName());
  for (  AmHostGroupInfo amHostGroupInfo : amHostGroupsInfo) {
    logger.info("String_Node_Str" + ApiUtils.objectToJson(amHostGroupInfo));
    for (    ApiConfigGroup group : apiConfigGroupList.getConfigGroups()) {
      logger.info("String_Node_Str" + ApiUtils.objectToJson(group));
      ApiConfigGroupInfo apiConfigGroupInfo=group.getApiConfigGroupInfo();
      if (apiConfigGroupInfo != null && apiConfigGroupInfo.getDesiredConfigs() != null) {
        List<String> newHosts=newHostsMap.get(amHostGroupInfo.getVolumesCount());
        logger.info("String_Node_Str" + ApiUtils.objectToJson(newHosts) + "String_Node_Str"+ amHostGroupInfo.getVolumesCount()+ "String_Node_Str");
        List<Map<String,Object>> configs=amHostGroupInfo.getConfigurations();
        for (        Map<String,Object> map : configs) {
          for (          String type : map.keySet()) {
            String serviceName=configTypeToService.get(type + "String_Node_Str");
            String configGroupName=apiConfigGroupInfo.getGroupName();
            Set<String> existedConfigGroupTags=existedConfigGroupMap.get(configGroupName);
            if (existedConfigGroupTags == null) {
              existedConfigGroupTags=new HashSet<String>();
            }
            if (amHostGroupInfo.getName().equals(configGroupName) && apiConfigGroupInfo.getTag().equals(serviceName) && (newHosts != null)) {
              logger.info("String_Node_Str" + ApiUtils.objectToJson(newHosts) + "String_Node_Str"+ configGroupName+ "String_Node_Str"+ serviceName+ "String_Node_Str");
              updateConfigGroup(apiConfigGroupInfo,clusterDef.getName(),amHostGroupInfo.toApiHostGroupForClusterBlueprint(),newHosts);
              existedConfigGroupTags.add(serviceName);
              existedConfigGroupMap.put(configGroupName,existedConfigGroupTags);
              break;
            }
            if (apiConfigGroupInfo.getTag().equals(serviceName) && isTheSameConfigGroup(apiConfigGroupInfo,amHostGroupInfo)) {
              logger.info("String_Node_Str" + configGroupName + "String_Node_Str"+ amHostGroupInfo.getName());
              apiConfigGroupInfo.setGroupName(amHostGroupInfo.getName());
              updateConfigGroup(apiConfigGroupInfo,clusterDef.getName(),amHostGroupInfo.toApiHostGroupForClusterBlueprint(),newHosts);
              existedConfigGroupTags.add(serviceName);
              existedConfigGroupMap.put(configGroupName,existedConfigGroupTags);
            }
          }
        }
      }
    }
  }
  createConfigGroups(clusterDef,nodeGroups,configTypeToService,existedConfigGroupMap);
}