Program: 95563
Project: 95563
Buggy source:
/** 
 * Deletes the given Component Name from the object map.
 * @param toDelete The Component Name to delete.
 * @return the category to which the Component Name belonged before it wasdeleted.
 */
public IObjectMappingCategoryPO deleteCompName(IComponentNamePO toDelete){
  IObjectMappingCategoryPO originalCategory=null;
  IWritableComponentNameMapper compNameMapper=getEditor().getEditorHelper().getEditSupport().getCompMapper();
  IObjectMappingAssoziationPO parent=getAssociation(toDelete.getGuid());
  try {
    compNameMapper.changeReuse(parent,toDelete.getGuid(),null);
    IObjectMappingCategoryPO category=parent.getCategory();
    originalCategory=category;
    if (parent.getLogicalNames().isEmpty()) {
      if (originalCategory != null) {
        originalCategory.removeAssociation(parent);
      }
      if (parent.getTechnicalName() != null) {
        Stack<String> catPath=new Stack<String>();
        while (category.getParent() != null) {
          catPath.push(category.getName());
          category=category.getParent();
        }
        IObjectMappingCategoryPO newCategory=getEditor().getAut().getObjMap().getUnmappedTechnicalCategory();
        while (!catPath.isEmpty()) {
          String catName=catPath.pop();
          IObjectMappingCategoryPO subcategory=findSubcategory(newCategory,catName);
          if (subcategory == null) {
            subcategory=PoMaker.createObjectMappingCategoryPO(catName);
            newCategory.addCategory(subcategory);
          }
          newCategory=subcategory;
        }
        newCategory.addAssociation(parent);
      }
 else {
        getEditor().getEditorHelper().getEditSupport().getSession().remove(parent);
      }
    }
    EntityManager sess=getEditor().getEditorHelper().getEditSupport().getSession();
    sess.detach(sess.find(toDelete.getClass(),toDelete.getId()));
    DataEventDispatcher.getInstance().fireDataChangedListener(getEditor().getAut().getObjMap(),DataState.StructureModified,UpdateState.onlyInEditor);
  }
 catch (  IncompatibleTypeException ite) {
    ErrorHandlingUtil.createMessageDialog(ite,ite.getErrorMessageParams(),null);
  }
catch (  PMException pme) {
    PMExceptionHandler.handlePMExceptionForEditor(pme,getEditor());
  }
  return originalCategory;
}

Fixed version (ground truth):
/** 
 * Deletes the given Component Name from the object map.
 * @param toDelete The Component Name to delete.
 * @return the category to which the Component Name belonged before it wasdeleted.
 */
public IObjectMappingCategoryPO deleteCompName(IComponentNamePO toDelete){
  IObjectMappingCategoryPO originalCategory=null;
  IWritableComponentNameMapper compNameMapper=getEditor().getEditorHelper().getEditSupport().getCompMapper();
  IObjectMappingAssoziationPO parent=getAssociation(toDelete.getGuid());
  try {
    compNameMapper.changeReuse(parent,toDelete.getGuid(),null);
    IObjectMappingCategoryPO category=parent.getCategory();
    originalCategory=category;
    if (parent.getLogicalNames().isEmpty()) {
      if (originalCategory != null) {
        originalCategory.removeAssociation(parent);
      }
      if (parent.getTechnicalName() != null) {
        Stack<String> catPath=new Stack<String>();
        while (category.getParent() != null) {
          catPath.push(category.getName());
          category=category.getParent();
        }
        IObjectMappingCategoryPO newCategory=getEditor().getAut().getObjMap().getUnmappedTechnicalCategory();
        while (!catPath.isEmpty()) {
          String catName=catPath.pop();
          IObjectMappingCategoryPO subcategory=findSubcategory(newCategory,catName);
          if (subcategory == null) {
            subcategory=PoMaker.createObjectMappingCategoryPO(catName);
            newCategory.addCategory(subcategory);
          }
          newCategory=subcategory;
        }
        newCategory.addAssociation(parent);
      }
 else {
        getEditor().getEditorHelper().getEditSupport().getSession().remove(parent);
      }
    }
    EntityManager sess=getEditor().getEditorHelper().getEditSupport().getSession();
    if (toDelete.getId() != null) {
      IComponentNamePO toRem=sess.find(toDelete.getClass(),toDelete.getId());
      if (toRem != null) {
        sess.detach(toRem);
      }
    }
    DataEventDispatcher.getInstance().fireDataChangedListener(getEditor().getAut().getObjMap(),DataState.StructureModified,UpdateState.onlyInEditor);
  }
 catch (  IncompatibleTypeException ite) {
    ErrorHandlingUtil.createMessageDialog(ite,ite.getErrorMessageParams(),null);
  }
catch (  PMException pme) {
    PMExceptionHandler.handlePMExceptionForEditor(pme,getEditor());
  }
  return originalCategory;
}