Program: 48275
Project: 48275
Buggy source:
private Map<String,List<ApiRole>> configureNodeServices(final CmClusterDef cluster,final ClusterReportQueue reportQueue,final List<String> addedNodeNames) throws SoftwareManagementPluginException {
  Map<String,String> nodeRefToName=cluster.hostIdToName();
  Map<String,List<CmRoleDef>> serviceRolesMap=new HashMap<String,List<CmRoleDef>>();
  Set<String> addedNodeNameSet=new HashSet<String>();
  addedNodeNameSet.addAll(addedNodeNames);
  for (  CmServiceDef serviceDef : cluster.getServices()) {
    List<CmRoleDef> roles=serviceDef.getRoles();
    for (    CmRoleDef role : roles) {
      String nodeId=role.getNodeRef();
      String nodeName=nodeRefToName.get(nodeId);
      if (addedNodeNameSet.contains(nodeName)) {
        List<CmRoleDef> roleDefs=serviceRolesMap.get(serviceDef.getName());
        if (roleDefs == null) {
          roleDefs=new ArrayList<CmRoleDef>();
          serviceRolesMap.put(serviceDef.getName(),roleDefs);
        }
        roleDefs.add(role);
      }
    }
  }
  Map<String,List<ApiRole>> result=new HashMap<>();
  try {
    ApiServiceList apiServiceList=apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName()).readServices(DataView.SUMMARY);
    for (    ApiService apiService : apiServiceList.getServices()) {
      if (!serviceRolesMap.containsKey(apiService.getName())) {
        continue;
      }
      result.put(apiService.getName(),new ArrayList<ApiRole>());
      List<CmRoleDef> roleDefs=serviceRolesMap.get(apiService.getName());
      List<ApiRole> apiRoles=apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName()).getRolesResource(apiService.getName()).readRoles().getRoles();
      logger.debug("String_Node_Str" + apiRoles);
      for (      ApiRole apiRole : apiRoles) {
        for (Iterator<CmRoleDef> ite=roleDefs.iterator(); ite.hasNext(); ) {
          CmRoleDef roleDef=ite.next();
          if (apiRole.getHostRef().getHostId().equals(roleDef.getNodeRef())) {
            ite.remove();
            result.get(apiService.getName()).add(apiRole);
            break;
          }
        }
      }
      if (!roleDefs.isEmpty()) {
        List<ApiRole> newRoles=new ArrayList<>();
        for (        CmRoleDef roleDef : roleDefs) {
          ApiRole apiRole=createApiRole(roleDef);
          newRoles.add(apiRole);
        }
        String action="String_Node_Str" + apiService.getDisplayName();
        cluster.getCurrentReport().setNodesAction(action,addedNodeNames);
        reportQueue.addClusterReport(cluster.getCurrentReport().clone());
        logger.debug("String_Node_Str" + newRoles);
        ApiRoleList roleList=apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName()).getRolesResource(apiService.getName()).createRoles(new ApiRoleList(newRoles));
        result.get(apiService.getName()).addAll(roleList.getRoles());
      }
    }
    logger.info("String_Node_Str");
    syncRolesId(cluster);
    preDeployConfig(cluster);
    for (    String serviceName : result.keySet()) {
      final ApiRoleNameList roleNameList=new ApiRoleNameList();
      final String sName=serviceName;
      List<String> roleNames=new ArrayList<>();
      for (      ApiRole apiRole : result.get(serviceName)) {
        roleNames.add(apiRole.getName());
      }
      roleNameList.setRoleNames(roleNames);
      retry(5,new Retriable(){
        @Override public void doWork() throws Exception {
          executeAndReport("String_Node_Str",addedNodeNames,apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName()).deployClientConfigCommand(sName,roleNameList),ProgressSplit.CONFIGURE_SERVICES.getProgress(),cluster.getCurrentReport(),reportQueue,true);
        }
      }
);
    }
    return result;
  }
 catch (  Exception e) {
    String errMsg="String_Node_Str" + ((e.getMessage() == null) ? "String_Node_Str" : ("String_Node_Str" + e.getMessage()));
    logger.error(errMsg);
    throw SoftwareManagementPluginException.CONFIGURE_SERVICE_FAILED(e);
  }
}

Fixed version (ground truth):
private Map<String,List<ApiRole>> configureNodeServices(final CmClusterDef cluster,final ClusterReportQueue reportQueue,final List<String> addedNodeNames) throws SoftwareManagementPluginException {
  Map<String,String> nodeRefToName=cluster.hostIdToName();
  Map<String,List<CmRoleDef>> serviceRolesMap=new HashMap<String,List<CmRoleDef>>();
  Set<String> addedNodeNameSet=new HashSet<String>();
  addedNodeNameSet.addAll(addedNodeNames);
  for (  CmServiceDef serviceDef : cluster.getServices()) {
    List<CmRoleDef> roles=serviceDef.getRoles();
    for (    CmRoleDef role : roles) {
      String nodeId=role.getNodeRef();
      String nodeName=nodeRefToName.get(nodeId);
      if (addedNodeNameSet.contains(nodeName)) {
        List<CmRoleDef> roleDefs=serviceRolesMap.get(serviceDef.getName());
        if (roleDefs == null) {
          roleDefs=new ArrayList<CmRoleDef>();
          serviceRolesMap.put(serviceDef.getName(),roleDefs);
        }
        roleDefs.add(role);
      }
    }
  }
  Map<String,List<ApiRole>> result=new HashMap<>();
  try {
    ApiServiceList apiServiceList=apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName()).readServices(DataView.SUMMARY);
    for (    ApiService apiService : apiServiceList.getServices()) {
      if (!serviceRolesMap.containsKey(apiService.getName())) {
        continue;
      }
      result.put(apiService.getName(),new ArrayList<ApiRole>());
      List<CmRoleDef> roleDefs=serviceRolesMap.get(apiService.getName());
      List<ApiRole> apiRoles=apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName()).getRolesResource(apiService.getName()).readRoles().getRoles();
      logger.debug("String_Node_Str" + apiRoles);
      for (      ApiRole apiRole : apiRoles) {
        for (Iterator<CmRoleDef> ite=roleDefs.iterator(); ite.hasNext(); ) {
          CmRoleDef roleDef=ite.next();
          if (apiRole.getHostRef().getHostId().equals(roleDef.getNodeRef())) {
            ite.remove();
            result.get(apiService.getName()).add(apiRole);
            break;
          }
        }
      }
      if (!roleDefs.isEmpty()) {
        List<ApiRole> newRoles=new ArrayList<>();
        for (        CmRoleDef roleDef : roleDefs) {
          ApiRole apiRole=createApiRole(roleDef);
          newRoles.add(apiRole);
        }
        String action="String_Node_Str" + apiService.getDisplayName();
        cluster.getCurrentReport().setNodesAction(action,addedNodeNames);
        reportQueue.addClusterReport(cluster.getCurrentReport().clone());
        logger.debug("String_Node_Str" + newRoles);
        ApiRoleList roleList=apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName()).getRolesResource(apiService.getName()).createRoles(new ApiRoleList(newRoles));
        result.get(apiService.getName()).addAll(roleList.getRoles());
      }
    }
    logger.info("String_Node_Str");
    syncRolesId(cluster);
    preDeployConfig(cluster);
    for (    String serviceName : result.keySet()) {
      final ApiRoleNameList roleNameList=new ApiRoleNameList();
      final String sName=serviceName;
      List<String> roleNames=new ArrayList<>();
      for (      ApiRole apiRole : result.get(serviceName)) {
        roleNames.add(apiRole.getName());
      }
      roleNameList.setRoleNames(roleNames);
      int sleepTime=Configuration.getInt("String_Node_Str",60);
      retry(10,sleepTime,new Retriable(){
        @Override public void doWork() throws Exception {
          executeAndReport("String_Node_Str",addedNodeNames,apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName()).deployClientConfigCommand(sName,roleNameList),ProgressSplit.CONFIGURE_SERVICES.getProgress(),cluster.getCurrentReport(),reportQueue,true);
        }
      }
);
    }
    return result;
  }
 catch (  Exception e) {
    String errMsg="String_Node_Str" + ((e.getMessage() == null) ? "String_Node_Str" : ("String_Node_Str" + e.getMessage()));
    logger.error(errMsg);
    throw SoftwareManagementPluginException.CONFIGURE_SERVICE_FAILED(e);
  }
}