Program: 44622
Project: 44622
Buggy source:
public void initializeIdentityStore(String cmsRepositoryId,CmsRepository identityStoreRepository){
  if (identityStoreRepository == null) {
    throw new CmsException("String_Node_Str");
  }
  try {
    Set<String> repIds=new HashSet<String>();
    repIds.add(cmsRepositoryId);
    repIds.add(identityStoreRepository.getId());
    if (CollectionUtils.isNotEmpty(roleXmlResources)) {
      logger.info("String_Node_Str" + identityStoreRepository.getId());
      String systemUserId=retrieveSystemRepositoryUserId();
      if (StringUtils.isBlank(systemUserId)) {
        logger.warn("String_Node_Str");
        return;
      }
      Map<String,ContentObject> rolesPerName=new HashMap<String,ContentObject>();
      for (      String repositoryId : repIds) {
        for (        Resource roleXmlResource : roleXmlResources) {
          ContentObject roleObject=importRole(roleXmlResource,systemUserId,repositoryId);
          if (roleObject != null) {
            rolesPerName.put(((StringProperty)roleObject.getCmsProperty("String_Node_Str")).getSimpleTypeValue(),roleObject);
          }
        }
        ContentObject roleCmsExternalViewerContentObject=rolesPerName.get(CmsRoleAffiliationFactory.INSTANCE.getCmsRoleAffiliationForRepository(CmsRole.ROLE_CMS_EXTERNAL_VIEWER,repositoryId));
        if (roleCmsExternalViewerContentObject.getId() == null) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_EXTERNAL_VIEWER);
        }
 else {
          ObjectReferenceProperty isMemberOfProperty=(ObjectReferenceProperty)roleCmsExternalViewerContentObject.getCmsProperty("String_Node_Str");
          if (isMemberOfProperty != null && isMemberOfProperty.hasValues()) {
            logger.warn("String_Node_Str" + roleCmsExternalViewerContentObject.getSystemName() + "String_Node_Str"+ CmsRoleAffiliationFactory.INSTANCE.getCmsRoleAffiliationForRepository(CmsRole.ROLE_CMS_EXTERNAL_VIEWER,repositoryId)+ "String_Node_Str"+ isMemberOfProperty.getSimpleTypeValues()+ "String_Node_Str");
            isMemberOfProperty.removeValues();
            contentService.save(roleCmsExternalViewerContentObject,false,true,null);
          }
        }
        if (addRoleAsMemberToRole(Arrays.asList(CmsRole.ROLE_CMS_EXTERNAL_VIEWER),CmsRole.ROLE_CMS_INTERNAL_VIEWER,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_INTERNAL_VIEWER);
        }
        List<CmsRole> roleCmsInternalViewerAsList=Arrays.asList(CmsRole.ROLE_CMS_INTERNAL_VIEWER);
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_EDITOR,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_EDITOR);
        }
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_PORTAL_EDITOR,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_PORTAL_EDITOR);
        }
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_TAXONOMY_EDITOR,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_TAXONOMY_EDITOR);
        }
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_WEB_SITE_PUBLISHER,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_WEB_SITE_PUBLISHER);
        }
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_IDENTITY_STORE_EDITOR,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_IDENTITY_STORE_EDITOR);
        }
        if (addRoleAsMemberToRole(Arrays.asList(CmsRole.ROLE_CMS_EDITOR,CmsRole.ROLE_CMS_PORTAL_EDITOR,CmsRole.ROLE_CMS_TAXONOMY_EDITOR,CmsRole.ROLE_CMS_WEB_SITE_PUBLISHER,CmsRole.ROLE_CMS_IDENTITY_STORE_EDITOR),CmsRole.ROLE_ADMIN,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_ADMIN);
        }
      }
    }
 else {
      logger.warn("String_Node_Str");
    }
  }
 catch (  Exception e) {
    logger.error("String_Node_Str",e);
    throw new CmsException(e);
  }
}

Fixed version (ground truth):
public void initializeIdentityStore(String cmsRepositoryId,CmsRepository identityStoreRepository){
  if (identityStoreRepository == null) {
    throw new CmsException("String_Node_Str");
  }
  try {
    Set<String> repIds=new HashSet<String>();
    repIds.add(cmsRepositoryId);
    repIds.add(identityStoreRepository.getId());
    if (CollectionUtils.isNotEmpty(roleXmlResources)) {
      logger.info("String_Node_Str" + identityStoreRepository.getId());
      String systemUserId=retrieveSystemRepositoryUserId();
      if (StringUtils.isBlank(systemUserId)) {
        logger.warn("String_Node_Str");
        return;
      }
      Map<String,ContentObject> rolesPerName=new HashMap<String,ContentObject>();
      for (      String repositoryId : repIds) {
        for (        Resource roleXmlResource : roleXmlResources) {
          ContentObject roleObject=importRole(roleXmlResource,systemUserId,repositoryId,identityStoreRepository.getId());
          if (roleObject != null) {
            rolesPerName.put(((StringProperty)roleObject.getCmsProperty("String_Node_Str")).getSimpleTypeValue(),roleObject);
          }
        }
        ContentObject roleCmsExternalViewerContentObject=rolesPerName.get(CmsRoleAffiliationFactory.INSTANCE.getCmsRoleAffiliationForRepository(CmsRole.ROLE_CMS_EXTERNAL_VIEWER,repositoryId));
        if (roleCmsExternalViewerContentObject.getId() == null) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_EXTERNAL_VIEWER);
        }
 else {
          ObjectReferenceProperty isMemberOfProperty=(ObjectReferenceProperty)roleCmsExternalViewerContentObject.getCmsProperty("String_Node_Str");
          if (isMemberOfProperty != null && isMemberOfProperty.hasValues()) {
            logger.warn("String_Node_Str" + roleCmsExternalViewerContentObject.getSystemName() + "String_Node_Str"+ CmsRoleAffiliationFactory.INSTANCE.getCmsRoleAffiliationForRepository(CmsRole.ROLE_CMS_EXTERNAL_VIEWER,repositoryId)+ "String_Node_Str"+ isMemberOfProperty.getSimpleTypeValues()+ "String_Node_Str");
            isMemberOfProperty.removeValues();
            contentService.save(roleCmsExternalViewerContentObject,false,true,null);
          }
        }
        if (addRoleAsMemberToRole(Arrays.asList(CmsRole.ROLE_CMS_EXTERNAL_VIEWER),CmsRole.ROLE_CMS_INTERNAL_VIEWER,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_INTERNAL_VIEWER);
        }
        List<CmsRole> roleCmsInternalViewerAsList=Arrays.asList(CmsRole.ROLE_CMS_INTERNAL_VIEWER);
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_EDITOR,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_EDITOR);
        }
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_PORTAL_EDITOR,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_PORTAL_EDITOR);
        }
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_TAXONOMY_EDITOR,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_TAXONOMY_EDITOR);
        }
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_WEB_SITE_PUBLISHER,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_WEB_SITE_PUBLISHER);
        }
        if (addRoleAsMemberToRole(roleCmsInternalViewerAsList,CmsRole.ROLE_CMS_IDENTITY_STORE_EDITOR,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_CMS_IDENTITY_STORE_EDITOR);
        }
        if (addRoleAsMemberToRole(Arrays.asList(CmsRole.ROLE_CMS_EDITOR,CmsRole.ROLE_CMS_PORTAL_EDITOR,CmsRole.ROLE_CMS_TAXONOMY_EDITOR,CmsRole.ROLE_CMS_WEB_SITE_PUBLISHER,CmsRole.ROLE_CMS_IDENTITY_STORE_EDITOR),CmsRole.ROLE_ADMIN,rolesPerName,repositoryId)) {
          saveRoleObject(rolesPerName,repositoryId,CmsRole.ROLE_ADMIN);
        }
      }
    }
 else {
      logger.warn("String_Node_Str");
    }
  }
 catch (  Exception e) {
    logger.error("String_Node_Str",e);
    throw new CmsException(e);
  }
}