Program: 48365
Project: 48365
Buggy source:
private void createConfigGroups(AmClusterDef clusterDef,List<AmNodeGroupDef> nodeGroups,Map<String,String> configTypeToService,List<String> existedConfigGroupNames){
  List<ApiConfigGroup> configGroups=new ArrayList<>();
  Map<String,ApiConfigGroup> serviceToGroup=new HashMap<>();
  for (  AmNodeGroupDef nodeGroup : nodeGroups) {
    for (    AmHostGroupInfo amHostGroupInfo : nodeGroup.generateHostGroupsInfo()) {
      if (existedConfigGroupNames.contains(amHostGroupInfo.getName())) {
        continue;
      }
      serviceToGroup.clear();
      List<Map<String,Object>> configs=amHostGroupInfo.getConfigurations();
      int i=1;
      for (      Map<String,Object> map : configs) {
        for (        String type : map.keySet()) {
          String serviceName=configTypeToService.get(type + "String_Node_Str");
          ApiConfigGroup confGroup=serviceToGroup.get(serviceName);
          if (confGroup == null) {
            confGroup=createConfigGroup(clusterDef,amHostGroupInfo,serviceName);
            serviceToGroup.put(serviceName,confGroup);
          }
          ApiConfigGroupConfiguration sameType=null;
          for (          ApiConfigGroupConfiguration config : confGroup.getApiConfigGroupInfo().getDesiredConfigs()) {
            if (config.getType().equals(type)) {
              sameType=config;
              break;
            }
          }
          if (sameType == null) {
            sameType=createApiConfigGroupConf(i,type,serviceName,confGroup);
          }
          Map<String,String> property=(Map<String,String>)map.get(type);
          sameType.getProperties().putAll(property);
        }
      }
      configGroups.addAll(serviceToGroup.values());
    }
  }
  if (configGroups.isEmpty()) {
    return;
  }
  logger.info("String_Node_Str" + configGroups);
  apiManager.createConfigGroups(clusterDef.getName(),configGroups);
}

Fixed version (ground truth):
private void createConfigGroups(AmClusterDef clusterDef,List<AmNodeGroupDef> nodeGroups,Map<String,String> configTypeToService,Map<String,Set<String>> existedConfigGroupMap){
  List<ApiConfigGroup> configGroups=new ArrayList<>();
  Map<String,ApiConfigGroup> serviceToGroup=new HashMap<>();
  for (  AmNodeGroupDef nodeGroup : nodeGroups) {
    for (    AmHostGroupInfo amHostGroupInfo : nodeGroup.generateHostGroupsInfo()) {
      serviceToGroup.clear();
      List<Map<String,Object>> configs=amHostGroupInfo.getConfigurations();
      int i=1;
      for (      Map<String,Object> map : configs) {
        for (        String type : map.keySet()) {
          String serviceName=configTypeToService.get(type + "String_Node_Str");
          Set<String> existedConfigGroupTags=existedConfigGroupMap.get(amHostGroupInfo.getName());
          if (CollectionUtils.isNotEmpty(existedConfigGroupTags) && existedConfigGroupTags.contains(serviceName)) {
            continue;
          }
          ApiConfigGroup confGroup=serviceToGroup.get(serviceName);
          if (confGroup == null) {
            confGroup=createConfigGroup(clusterDef,amHostGroupInfo,serviceName);
            serviceToGroup.put(serviceName,confGroup);
          }
          ApiConfigGroupConfiguration sameType=null;
          for (          ApiConfigGroupConfiguration config : confGroup.getApiConfigGroupInfo().getDesiredConfigs()) {
            if (config.getType().equals(type)) {
              sameType=config;
              break;
            }
          }
          if (sameType == null) {
            sameType=createApiConfigGroupConf(i,type,serviceName,confGroup);
          }
          Map<String,String> property=(Map<String,String>)map.get(type);
          sameType.getProperties().putAll(property);
        }
      }
      configGroups.addAll(serviceToGroup.values());
    }
  }
  if (configGroups.isEmpty()) {
    return;
  }
  logger.info("String_Node_Str" + configGroups);
  apiManager.createConfigGroups(clusterDef.getName(),configGroups);
}