Program: 44635
Project: 44635
Buggy source:
public Taxonomy saveTaxonomy(Object taxonomySource){
  if (taxonomySource == null) {
    throw new CmsException("String_Node_Str");
  }
  if (taxonomySource instanceof String) {
    return importDao.importTaxonomy((String)taxonomySource,ImportMode.SAVE_ENTITY_TREE);
  }
  if (!(taxonomySource instanceof Taxonomy)) {
    throw new CmsException("String_Node_Str" + taxonomySource.getClass().getName());
  }
  Taxonomy taxonomy=(Taxonomy)taxonomySource;
  if (StringUtils.isBlank(taxonomy.getName())) {
    throw new CmsException("String_Node_Str");
  }
  changeIdentifierIfTaxonomyIsBuiltIn(taxonomy,Taxonomy.SUBJECT_TAXONOMY_NAME);
  String taxonomyName=taxonomy.getName();
  boolean taxonomyNameIsAReservedName=isTaxonomyNameAReservedName(taxonomyName);
  if (!taxonomyNameIsAReservedName) {
    if (!XMLChar.isValidNCName(taxonomyName)) {
      throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str");
    }
 else     if (!cmsRepositoryEntityUtils.isValidSystemName(taxonomyName)) {
      throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ CmsConstants.SYSTEM_NAME_REG_EXP);
    }
  }
  Session session=null;
  SaveMode saveMode=null;
  try {
    saveMode=StringUtils.isBlank(taxonomy.getId()) ? SaveMode.INSERT : SaveMode.UPDATE_ALL;
    session=getSession();
    Node taxonomyRootJcrNode=JcrNodeUtils.getTaxonomyRootNode(session);
    Node taxonomyJcrNode=null;
switch (saveMode) {
case INSERT:
      throwExceptionIfTaxonomyNameExists(taxonomy,taxonomyRootJcrNode);
    if (taxonomyNameIsAReservedName) {
      throw new CmsException("String_Node_Str" + taxonomy.getName());
    }
  taxonomyJcrNode=taxonomyRootJcrNode.addNode(taxonomyName,CmsBuiltInItem.Taxonomy.getJcrName());
cmsRepositoryEntityUtils.createCmsIdentifier(taxonomyJcrNode,taxonomy,false);
break;
case UPDATE_ALL:
if (Taxonomy.SUBJECT_TAXONOMY_NAME.equalsIgnoreCase(taxonomyName)) {
taxonomyJcrNode=taxonomyRootJcrNode.getNode(Taxonomy.SUBJECT_TAXONOMY_NAME);
}
 else {
taxonomyJcrNode=cmsRepositoryEntityUtils.retrieveUniqueNodeForCmsRepositoryEntity(session,taxonomy);
}
if (taxonomyJcrNode == null) {
if (taxonomyNameIsAReservedName) {
throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ taxonomy.getId());
}
if (taxonomyRootJcrNode.hasNode(taxonomyName)) {
if (cmsRepositoryEntityUtils.hasCmsIdentifier(taxonomyRootJcrNode.getNode(taxonomyName))) {
String taxonomyJcrNodeIdentifier=cmsRepositoryEntityUtils.getCmsIdentifier(taxonomyRootJcrNode.getNode(taxonomyName));
if (StringUtils.equals(taxonomyJcrNodeIdentifier,taxonomy.getId())) {
  logger.warn("String_Node_Str" + taxonomy.getId() + "String_Node_Str"+ "String_Node_Str"+ taxonomyName+ "String_Node_Str"+ taxonomy.getId()+ "String_Node_Str");
  taxonomyJcrNode=taxonomyRootJcrNode.getNode(taxonomyName);
}
 else {
  throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ taxonomyJcrNodeIdentifier+ "String_Node_Str"+ taxonomy.getId());
}
}
 else {
throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ "String_Node_Str"+ taxonomy.getId());
}
}
 else {
taxonomyJcrNode=taxonomyRootJcrNode.addNode(taxonomyName,CmsBuiltInItem.Taxonomy.getJcrName());
cmsRepositoryEntityUtils.createCmsIdentifier(taxonomyJcrNode,taxonomy,true);
}
}
if (taxonomyJcrNode.getParent() == null || (!taxonomyJcrNode.getParent().isNodeType(CmsBuiltInItem.RepositoryUser.getJcrName()) && !taxonomyJcrNode.getParent().isNodeType(CmsBuiltInItem.TaxonomyRoot.getJcrName()))) {
throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ taxonomyJcrNode.getPath());
}
if (!taxonomyJcrNode.getName().equals(taxonomyName)) {
if (isTaxonomyNameAReservedName(taxonomyJcrNode.getName())) {
throw new CmsException("String_Node_Str" + taxonomyJcrNode.getName() + "String_Node_Str");
}
throwExceptionIfTaxonomyNameExists(taxonomy,taxonomyRootJcrNode);
if (!taxonomyNameIsAReservedName) {
session.move(taxonomyJcrNode.getPath(),taxonomyRootJcrNode.getPath() + CmsConstants.FORWARD_SLASH + taxonomyName);
}
}
break;
default :
break;
}
if (taxonomyJcrNode != null) {
cmsLocalizationUtils.updateCmsLocalization(taxonomy,taxonomyJcrNode);
cmsRepositoryEntityUtils.setSystemProperties(taxonomyJcrNode,taxonomy);
}
if (SaveMode.INSERT == saveMode) {
saveRootTopics(taxonomy);
}
session.save();
return taxonomy;
}
 catch (CmsException e) {
throw e;
}
catch (Exception e) {
throw new CmsException(e);
}
}

Fixed version (ground truth):
public Taxonomy saveTaxonomy(Object taxonomySource){
  if (taxonomySource == null) {
    throw new CmsException("String_Node_Str");
  }
  if (taxonomySource instanceof String) {
    ImportConfiguration configuration=ImportConfiguration.taxonomy().persist(PersistMode.PERSIST_ENTITY_TREE).build();
    return importDao.importTaxonomy((String)taxonomySource,configuration);
  }
  if (!(taxonomySource instanceof Taxonomy)) {
    throw new CmsException("String_Node_Str" + taxonomySource.getClass().getName());
  }
  Taxonomy taxonomy=(Taxonomy)taxonomySource;
  if (StringUtils.isBlank(taxonomy.getName())) {
    if (!StringUtils.isBlank(taxonomy.getId())) {
      try {
        Node taxonomyNode=getTaxonomyNodeByIdOrName(getSession(),taxonomy.getId());
        if (taxonomyNode == null) {
          throw new CmsException("String_Node_Str" + taxonomy.getId() + "String_Node_Str");
        }
 else {
          taxonomy.setName(taxonomyNode.getName());
        }
      }
 catch (      RepositoryException e) {
        throw new CmsException(e);
      }
    }
 else {
      throw new CmsException("String_Node_Str");
    }
  }
  changeIdentifierIfTaxonomyIsBuiltIn(taxonomy,Taxonomy.SUBJECT_TAXONOMY_NAME);
  String taxonomyName=taxonomy.getName();
  boolean taxonomyNameIsAReservedName=isTaxonomyNameAReservedName(taxonomyName);
  if (!taxonomyNameIsAReservedName) {
    if (!XMLChar.isValidNCName(taxonomyName)) {
      throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str");
    }
 else     if (!cmsRepositoryEntityUtils.isValidSystemName(taxonomyName)) {
      throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ CmsConstants.SYSTEM_NAME_REG_EXP);
    }
  }
  Session session=null;
  SaveMode saveMode=null;
  try {
    saveMode=StringUtils.isBlank(taxonomy.getId()) ? SaveMode.INSERT : SaveMode.UPDATE;
    session=getSession();
    Node taxonomyRootJcrNode=JcrNodeUtils.getTaxonomyRootNode(session);
    Node taxonomyJcrNode=null;
switch (saveMode) {
case INSERT:
      throwExceptionIfTaxonomyNameExists(taxonomy,taxonomyRootJcrNode);
    if (taxonomyNameIsAReservedName) {
      throw new CmsException("String_Node_Str" + taxonomy.getName());
    }
  taxonomyJcrNode=taxonomyRootJcrNode.addNode(taxonomyName,CmsBuiltInItem.Taxonomy.getJcrName());
cmsRepositoryEntityUtils.createCmsIdentifier(taxonomyJcrNode,taxonomy,false);
break;
case UPDATE:
if (Taxonomy.SUBJECT_TAXONOMY_NAME.equalsIgnoreCase(taxonomyName)) {
taxonomyJcrNode=taxonomyRootJcrNode.getNode(Taxonomy.SUBJECT_TAXONOMY_NAME);
}
 else {
taxonomyJcrNode=cmsRepositoryEntityUtils.retrieveUniqueNodeForCmsRepositoryEntity(session,taxonomy);
}
if (taxonomyJcrNode == null) {
if (taxonomyNameIsAReservedName) {
throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ taxonomy.getId());
}
if (taxonomyRootJcrNode.hasNode(taxonomyName)) {
if (cmsRepositoryEntityUtils.hasCmsIdentifier(taxonomyRootJcrNode.getNode(taxonomyName))) {
String taxonomyJcrNodeIdentifier=cmsRepositoryEntityUtils.getCmsIdentifier(taxonomyRootJcrNode.getNode(taxonomyName));
if (StringUtils.equals(taxonomyJcrNodeIdentifier,taxonomy.getId())) {
  logger.warn("String_Node_Str" + taxonomy.getId() + "String_Node_Str"+ "String_Node_Str"+ taxonomyName+ "String_Node_Str"+ taxonomy.getId()+ "String_Node_Str");
  taxonomyJcrNode=taxonomyRootJcrNode.getNode(taxonomyName);
}
 else {
  throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ taxonomyJcrNodeIdentifier+ "String_Node_Str"+ taxonomy.getId());
}
}
 else {
throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ "String_Node_Str"+ taxonomy.getId());
}
}
 else {
taxonomyJcrNode=taxonomyRootJcrNode.addNode(taxonomyName,CmsBuiltInItem.Taxonomy.getJcrName());
cmsRepositoryEntityUtils.createCmsIdentifier(taxonomyJcrNode,taxonomy,true);
}
}
if (taxonomyJcrNode.getParent() == null || (!taxonomyJcrNode.getParent().isNodeType(CmsBuiltInItem.RepositoryUser.getJcrName()) && !taxonomyJcrNode.getParent().isNodeType(CmsBuiltInItem.TaxonomyRoot.getJcrName()))) {
throw new CmsException("String_Node_Str" + taxonomyName + "String_Node_Str"+ taxonomyJcrNode.getPath());
}
if (!taxonomyJcrNode.getName().equals(taxonomyName)) {
if (isTaxonomyNameAReservedName(taxonomyJcrNode.getName())) {
throw new CmsException("String_Node_Str" + taxonomyJcrNode.getName() + "String_Node_Str");
}
throwExceptionIfTaxonomyNameExists(taxonomy,taxonomyRootJcrNode);
if (!taxonomyNameIsAReservedName) {
session.move(taxonomyJcrNode.getPath(),taxonomyRootJcrNode.getPath() + CmsConstants.FORWARD_SLASH + taxonomyName);
}
}
break;
default :
break;
}
if (taxonomyJcrNode != null) {
cmsLocalizationUtils.updateCmsLocalization(taxonomy,taxonomyJcrNode);
}
if (SaveMode.INSERT == saveMode) {
saveRootTopics(taxonomy);
}
session.save();
return taxonomy;
}
 catch (CmsException e) {
throw e;
}
catch (Exception e) {
throw new CmsException(e);
}
}