Program: 126276
Project: 126276
Buggy source:
/** 
 * check the item is valid or not。
 */
public boolean checkItem(ResourcesManager resManager,ImportItem importItem,boolean overwrite){
  try {
    Item item=importItem.getItem();
    ERepositoryObjectType itemType=ERepositoryObjectType.getItemType(item);
    if (itemType == null) {
      importItem.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    if (item.getState() == null) {
      importItem.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    final RepositoryObjectCache repObjectcache=ImportCacheHelper.getInstance().getRepObjectcache();
    repObjectcache.initialize(itemType);
    IRepositoryViewObject itemWithSameIdObj=null;
    IRepositoryViewObject itemWithSameNameObj=null;
    for (    IRepositoryViewObject current : repObjectcache.getItemsFromRepository().get(itemType)) {
      final Property property=importItem.getProperty();
      if (property != null) {
        if (isSameName(importItem,current)) {
          itemWithSameNameObj=current;
        }
        if (property.getId() != null && property.getId().equals(current.getId())) {
          itemWithSameIdObj=current;
        }
      }
    }
    boolean nameAvailable=itemWithSameNameObj == null;
    boolean idAvailable=itemWithSameIdObj == null;
    if (nameAvailable) {
      if (!idAvailable) {
        importItem.setState(State.ID_EXISTED);
        importItem.setExistingItemWithSameId(itemWithSameIdObj);
      }
    }
 else {
      if (idAvailable) {
        importItem.setState(State.NAME_EXISTED);
        if (overwrite) {
          importItem.setExistingItemWithSameId(itemWithSameNameObj);
          if (itemWithSameNameObj != null) {
            ERepositoryStatus status=itemWithSameNameObj.getRepositoryStatus();
            if (status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
              importItem.addError(Messages.getString("String_Node_Str"));
            }
          }
        }
      }
 else {
        importItem.setState(State.NAME_AND_ID_EXISTED);
        if (overwrite) {
          importItem.setExistingItemWithSameId(itemWithSameNameObj);
        }
      }
      if (!overwrite) {
        importItem.addError(Messages.getString("String_Node_Str"));
      }
    }
    if (overwrite && importItem.getState() == State.NAME_AND_ID_EXISTED) {
      if (checkIfLocked(importItem)) {
        importItem.addError(Messages.getString("String_Node_Str"));
      }
    }
  }
 catch (  PersistenceException e) {
    log.error("String_Node_Str" + importItem.getPath(),e);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * check the item is valid or not。
 */
public boolean checkItem(ResourcesManager resManager,ImportItem importItem,boolean overwrite){
  try {
    Item item=importItem.getItem();
    ERepositoryObjectType itemType=ERepositoryObjectType.getItemType(item);
    if (itemType == null) {
      importItem.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    if (item.getState() == null) {
      importItem.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    final RepositoryObjectCache repObjectcache=ImportCacheHelper.getInstance().getRepObjectcache();
    IRepositoryViewObject itemWithSameIdObj=null;
    IRepositoryViewObject itemWithSameNameObj=null;
    List<IRepositoryViewObject> repViewObjectList=null;
    List<ERepositoryObjectType> allTypesOfProcess=ERepositoryObjectType.getAllTypesOfProcess();
    if (allTypesOfProcess.contains(itemType)) {
      for (      ERepositoryObjectType curProcessType : allTypesOfProcess) {
        repObjectcache.initialize(curProcessType);
      }
      Map<ERepositoryObjectType,List<IRepositoryViewObject>> itemsMap=repObjectcache.getItemsFromRepository();
      repViewObjectList=new LinkedList<IRepositoryViewObject>();
      for (      ERepositoryObjectType curProcessType : allTypesOfProcess) {
        List<IRepositoryViewObject> itemList=itemsMap.get(curProcessType);
        if (itemList != null) {
          repViewObjectList.addAll(itemList);
        }
      }
    }
 else {
      repObjectcache.initialize(itemType);
      repViewObjectList=repObjectcache.getItemsFromRepository().get(itemType);
    }
    Iterator<IRepositoryViewObject> repoViewObjectIter=repViewObjectList.iterator();
    boolean isSameRepositoryType=true;
    while (repoViewObjectIter.hasNext()) {
      IRepositoryViewObject current=repoViewObjectIter.next();
      final Property property=importItem.getProperty();
      if (property != null) {
        if (isSameName(importItem,current)) {
          itemWithSameNameObj=current;
          if (importItem.getRepositoryType() == current.getRepositoryObjectType()) {
            isSameRepositoryType=true;
          }
 else {
            isSameRepositoryType=false;
          }
        }
        if (property.getId() != null && property.getId().equals(current.getId())) {
          itemWithSameIdObj=current;
        }
      }
    }
    boolean nameAvailable=itemWithSameNameObj == null;
    boolean idAvailable=itemWithSameIdObj == null;
    if (nameAvailable) {
      if (!idAvailable) {
        importItem.setState(State.ID_EXISTED);
        importItem.setExistingItemWithSameId(itemWithSameIdObj);
      }
    }
 else {
      if (idAvailable) {
        importItem.setState(State.NAME_EXISTED);
        if (overwrite && isSameRepositoryType) {
          importItem.setExistingItemWithSameId(itemWithSameNameObj);
          if (itemWithSameNameObj != null) {
            ERepositoryStatus status=itemWithSameNameObj.getRepositoryStatus();
            if (status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
              importItem.addError(Messages.getString("String_Node_Str"));
            }
          }
        }
      }
 else {
        importItem.setState(State.NAME_AND_ID_EXISTED);
        if (overwrite) {
          importItem.setExistingItemWithSameId(itemWithSameNameObj);
        }
      }
      if (isSameRepositoryType) {
        if (!overwrite) {
          importItem.addError(Messages.getString("String_Node_Str"));
        }
      }
 else {
        importItem.addError(Messages.getString("String_Node_Str"));
      }
    }
    if (overwrite && importItem.getState() == State.NAME_AND_ID_EXISTED && isSameRepositoryType) {
      if (checkIfLocked(importItem)) {
        importItem.addError(Messages.getString("String_Node_Str"));
      }
    }
  }
 catch (  PersistenceException e) {
    log.error("String_Node_Str" + importItem.getPath(),e);
  }
  return true;
}