Program: 121434
Project: 121434
Buggy source:
private boolean checkItem(ItemRecord itemRecord,boolean overwrite){
  boolean result=false;
  try {
    Item item=itemRecord.getItem();
    if (item instanceof TDQItem) {
      return false;
    }
    ERepositoryObjectType itemType=ERepositoryObjectType.getItemType(item);
    if (itemType == null) {
      itemRecord.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    cache.initialize(itemType);
    boolean isAllowMultipleName=(itemType == ERepositoryObjectType.SQLPATTERNS || itemType == ERepositoryObjectType.METADATA_FILE_XML);
    String itemPath=null;
    if (item.getState() != null) {
      itemPath=item.getState().getPath();
    }
    boolean nameAvailable=true;
    IRepositoryViewObject itemWithSameId=null;
    IRepositoryViewObject itemWithSameName=null;
    for (    IRepositoryViewObject current : cache.getItemsFromRepository().get(itemType)) {
      final Property property=itemRecord.getProperty();
      if (property != null) {
        if (property.getLabel() != null && property.getLabel().equalsIgnoreCase(current.getLabel()) && property.getId() != current.getId()) {
          if (!isAllowMultipleName || current.getPath().equals(itemPath)) {
            nameAvailable=false;
          }
          if (!nameAvailable) {
            itemWithSameName=current;
          }
        }
        if (property.getId() != null && property.getId().equalsIgnoreCase(current.getId())) {
          itemWithSameId=current;
        }
      }
    }
    itemRecord.setExistingItemWithSameId(itemWithSameId);
    boolean idAvailable=itemWithSameId == null;
    boolean isSystem=false;
    if (item.eClass().equals(PropertiesPackage.eINSTANCE.getRoutineItem())) {
      RoutineItem routineItem=(RoutineItem)item;
      if (item instanceof RoutineItem) {
        RoutineItem rItem=(RoutineItem)item;
        Set<String> set=routineExtModulesMap.get(rItem.getProperty().getId());
        if (set == null) {
          set=new HashSet<String>();
          routineExtModulesMap.put(rItem.getProperty().getId(),set);
        }
        for (        IMPORTType type : (List<IMPORTType>)rItem.getImports()) {
          set.add(type.getMODULE());
        }
      }
      if (routineItem.isBuiltIn()) {
        isSystem=true;
      }
    }
    if (item.eClass().equals(PropertiesPackage.eINSTANCE.getSQLPatternItem())) {
      SQLPatternItem sqlPatternItem=(SQLPatternItem)item;
      if (sqlPatternItem.isSystem()) {
        isSystem=true;
      }
    }
    if (isSystem) {
      itemRecord.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    if (nameAvailable) {
      if (idAvailable) {
        if (!isSystem) {
          result=true;
        }
      }
 else {
        itemRecord.setState(State.ID_EXISTED);
        result=true;
      }
    }
 else {
      if (idAvailable) {
        itemRecord.setState(State.NAME_EXISTED);
        if (!isSystem && overwrite) {
          itemRecord.setExistingItemWithSameId(itemWithSameName);
          result=true;
        }
        if (result && overwrite && itemWithSameName != null) {
          ERepositoryStatus status=itemWithSameName.getRepositoryStatus();
          if (status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
            itemRecord.addError(Messages.getString("String_Node_Str"));
            return false;
          }
        }
      }
 else {
        itemRecord.setState(State.NAME_AND_ID_EXISTED);
        if (overwrite) {
          result=true;
        }
        if (!isSystem && overwrite && !itemWithSameName.getProperty().getLabel().equals(itemWithSameId.getProperty().getLabel())) {
          itemRecord.setExistingItemWithSameId(itemWithSameName);
          result=true;
        }
      }
      if (!result && !isSystem) {
        itemRecord.addError(Messages.getString("String_Node_Str"));
      }
    }
    if (result && overwrite && itemRecord.getState() == State.NAME_AND_ID_EXISTED) {
      if (checkIfLocked(itemRecord)) {
        itemRecord.addError(Messages.getString("String_Node_Str"));
        result=false;
      }
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + itemRecord.getPath(),e);
  }
  return result;
}

Fixed version (ground truth):
private boolean checkItem(ItemRecord itemRecord,boolean overwrite){
  boolean result=false;
  try {
    Item item=itemRecord.getItem();
    if (item instanceof TDQItem) {
      return false;
    }
    ERepositoryObjectType itemType=ERepositoryObjectType.getItemType(item);
    if (itemType == null) {
      itemRecord.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    cache.initialize(itemType);
    boolean isAllowMultipleName=(itemType == ERepositoryObjectType.SQLPATTERNS || itemType == ERepositoryObjectType.METADATA_FILE_XML);
    String itemPath=null;
    if (item.getState() != null) {
      itemPath=item.getState().getPath();
    }
 else {
      itemRecord.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    boolean nameAvailable=true;
    IRepositoryViewObject itemWithSameId=null;
    IRepositoryViewObject itemWithSameName=null;
    for (    IRepositoryViewObject current : cache.getItemsFromRepository().get(itemType)) {
      final Property property=itemRecord.getProperty();
      if (property != null) {
        if (property.getLabel() != null && property.getLabel().equalsIgnoreCase(current.getLabel()) && property.getId() != current.getId()) {
          if (!isAllowMultipleName || current.getPath().equals(itemPath)) {
            nameAvailable=false;
          }
          if (!nameAvailable) {
            itemWithSameName=current;
          }
        }
        if (property.getId() != null && property.getId().equalsIgnoreCase(current.getId())) {
          itemWithSameId=current;
        }
      }
    }
    itemRecord.setExistingItemWithSameId(itemWithSameId);
    boolean idAvailable=itemWithSameId == null;
    boolean isSystem=false;
    if (item.eClass().equals(PropertiesPackage.eINSTANCE.getRoutineItem())) {
      RoutineItem routineItem=(RoutineItem)item;
      if (item instanceof RoutineItem) {
        RoutineItem rItem=(RoutineItem)item;
        Set<String> set=routineExtModulesMap.get(rItem.getProperty().getId());
        if (set == null) {
          set=new HashSet<String>();
          routineExtModulesMap.put(rItem.getProperty().getId(),set);
        }
        for (        IMPORTType type : (List<IMPORTType>)rItem.getImports()) {
          set.add(type.getMODULE());
        }
      }
      if (routineItem.isBuiltIn()) {
        isSystem=true;
      }
    }
    if (item.eClass().equals(PropertiesPackage.eINSTANCE.getSQLPatternItem())) {
      SQLPatternItem sqlPatternItem=(SQLPatternItem)item;
      if (sqlPatternItem.isSystem()) {
        isSystem=true;
      }
    }
    if (isSystem) {
      itemRecord.addError(Messages.getString("String_Node_Str"));
      return false;
    }
    if (nameAvailable) {
      if (idAvailable) {
        if (!isSystem) {
          result=true;
        }
      }
 else {
        itemRecord.setState(State.ID_EXISTED);
        result=true;
      }
    }
 else {
      if (idAvailable) {
        itemRecord.setState(State.NAME_EXISTED);
        if (!isSystem && overwrite) {
          itemRecord.setExistingItemWithSameId(itemWithSameName);
          result=true;
        }
        if (result && overwrite && itemWithSameName != null) {
          ERepositoryStatus status=itemWithSameName.getRepositoryStatus();
          if (status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
            itemRecord.addError(Messages.getString("String_Node_Str"));
            return false;
          }
        }
      }
 else {
        itemRecord.setState(State.NAME_AND_ID_EXISTED);
        if (overwrite) {
          result=true;
        }
        if (!isSystem && overwrite && !itemWithSameName.getProperty().getLabel().equals(itemWithSameId.getProperty().getLabel())) {
          itemRecord.setExistingItemWithSameId(itemWithSameName);
          result=true;
        }
      }
      if (!result && !isSystem) {
        itemRecord.addError(Messages.getString("String_Node_Str"));
      }
    }
    if (result && overwrite && itemRecord.getState() == State.NAME_AND_ID_EXISTED) {
      if (checkIfLocked(itemRecord)) {
        itemRecord.addError(Messages.getString("String_Node_Str"));
        result=false;
      }
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + itemRecord.getPath(),e);
  }
  return result;
}