Program: 44623
Project: 44623
Buggy source:
public void createSystemPerson(String cmsRepositoryId,String identityStoreId){
  InputStream inputStream=null;
  try {
    ContentObjectCriteria personCriteria=CmsCriteriaFactory.newContentObjectCriteria("String_Node_Str");
    personCriteria.addCriterion(CriterionFactory.equalsCaseInsensitive("String_Node_Str",IdentityPrincipal.SYSTEM));
    personCriteria.setOffsetAndLimit(0,1);
    personCriteria.doNotCacheResults();
    CmsOutcome<ContentObject> outcome=contentService.searchContentObjects(personCriteria,ResourceRepresentationType.CONTENT_OBJECT_LIST);
    ContentObject systemPersonObject=null;
    boolean systemUpdated=false;
    if (outcome != null && outcome.getCount() > 0) {
      if (outcome.getCount() > 1) {
        logger.warn("String_Node_Str" + "String_Node_Str");
        return;
      }
 else {
        systemPersonObject=outcome.getResults().get(0);
      }
    }
 else {
      logger.info("String_Node_Str");
      if (systemPersonXmlResource == null || !systemPersonXmlResource.exists()) {
        throw new CmsException("String_Node_Str");
      }
 else {
        inputStream=systemPersonXmlResource.getInputStream();
        String systemPersonXml=IOUtils.toString(inputStream,"String_Node_Str");
        String systemUserId=retrieveSystemRepositoryUserId();
        if (StringUtils.isBlank(systemUserId)) {
          logger.warn("String_Node_Str");
          return;
        }
        systemPersonXml=StringUtils.replace(systemPersonXml,SYSTEM_USER_ID,systemUserId);
        ImportConfiguration configuration=ImportConfiguration.object().persist(PersistMode.DO_NOT_PERSIST).build();
        systemPersonObject=importDao.importContentObject(systemPersonXml,configuration);
        if (systemPersonObject == null) {
          throw new CmsException("String_Node_Str");
        }
        systemUpdated=true;
      }
    }
    ObjectReferenceProperty systemRoleProperty=(ObjectReferenceProperty)systemPersonObject.getCmsProperty("String_Node_Str");
    systemUpdated=fixRolesForSystemIfBroken(systemRoleProperty,cmsRepositoryId) || systemUpdated;
    if (!StringUtils.equals(cmsRepositoryId,identityStoreId)) {
      systemUpdated=fixRolesForSystemIfBroken(systemRoleProperty,identityStoreId) || systemUpdated;
    }
    if (systemUpdated) {
      contentService.save(systemPersonObject,false,true,null);
    }
  }
 catch (  CmsException e) {
    logger.error("String_Node_Str",e);
    throw e;
  }
catch (  Exception e) {
    logger.error("String_Node_Str",e);
    throw new CmsException(e);
  }
 finally {
    if (inputStream != null) {
      IOUtils.closeQuietly(inputStream);
    }
  }
}

Fixed version (ground truth):
public void createSystemPerson(String cmsRepositoryId,String idOfTheRepositoryWhichRepresentsTheIdentityStore){
  InputStream inputStream=null;
  try {
    ContentObjectCriteria personCriteria=CmsCriteriaFactory.newContentObjectCriteria("String_Node_Str");
    personCriteria.addCriterion(CriterionFactory.equalsCaseInsensitive("String_Node_Str",IdentityPrincipal.SYSTEM));
    personCriteria.setOffsetAndLimit(0,1);
    personCriteria.doNotCacheResults();
    CmsOutcome<ContentObject> outcome=contentService.searchContentObjects(personCriteria,ResourceRepresentationType.CONTENT_OBJECT_LIST);
    ContentObject systemPersonObject=null;
    boolean systemUpdated=false;
    if (outcome != null && outcome.getCount() > 0) {
      if (outcome.getCount() > 1) {
        logger.warn("String_Node_Str" + "String_Node_Str");
        return;
      }
 else {
        systemPersonObject=outcome.getResults().get(0);
      }
    }
 else {
      logger.info("String_Node_Str");
      if (systemPersonXmlResource == null || !systemPersonXmlResource.exists()) {
        throw new CmsException("String_Node_Str");
      }
 else {
        inputStream=systemPersonXmlResource.getInputStream();
        String systemPersonXml=IOUtils.toString(inputStream,"String_Node_Str");
        String systemUserId=retrieveSystemRepositoryUserId();
        if (StringUtils.isBlank(systemUserId)) {
          logger.warn("String_Node_Str");
          return;
        }
        systemPersonXml=StringUtils.replace(systemPersonXml,SYSTEM_USER_ID,systemUserId);
        systemPersonXml=StringUtils.replace(systemPersonXml,IDENTITY_STORE_REPOSITORY_ID,idOfTheRepositoryWhichRepresentsTheIdentityStore);
        ImportConfiguration configuration=ImportConfiguration.object().persist(PersistMode.DO_NOT_PERSIST).build();
        systemPersonObject=importDao.importContentObject(systemPersonXml,configuration);
        if (systemPersonObject == null) {
          throw new CmsException("String_Node_Str");
        }
        systemUpdated=true;
      }
    }
    ObjectReferenceProperty systemRoleProperty=(ObjectReferenceProperty)systemPersonObject.getCmsProperty("String_Node_Str");
    systemUpdated=fixRolesForSystemIfBroken(systemRoleProperty,cmsRepositoryId) || systemUpdated;
    if (!StringUtils.equals(cmsRepositoryId,idOfTheRepositoryWhichRepresentsTheIdentityStore)) {
      systemUpdated=fixRolesForSystemIfBroken(systemRoleProperty,idOfTheRepositoryWhichRepresentsTheIdentityStore) || systemUpdated;
    }
    if (systemUpdated) {
      contentService.save(systemPersonObject,false,true,null);
    }
  }
 catch (  CmsException e) {
    logger.error("String_Node_Str",e);
    throw e;
  }
catch (  Exception e) {
    logger.error("String_Node_Str",e);
    throw new CmsException(e);
  }
 finally {
    if (inputStream != null) {
      IOUtils.closeQuietly(inputStream);
    }
  }
}