Program: 3515
Project: 3515
Buggy source:
/** 
 * Index the given item
 * @param item  the item to index
 * @throws BrowseException
 */
private void indexItem(ItemMetadataProxy item) throws BrowseException {
  Map<String,String> itemMDMap=new HashMap<String,String>();
  try {
    boolean reqCommunityMappings=false;
    Map<Integer,String> sortMap=getSortValues(item,itemMDMap);
    if (item.isArchived() && !item.isWithdrawn()) {
      if (!dao.updateIndex(BrowseIndex.getItemBrowseIndex().getTableName(),item.getID(),sortMap)) {
        removeIndex(item.getID(),BrowseIndex.getWithdrawnBrowseIndex().getTableName());
        dao.insertIndex(BrowseIndex.getItemBrowseIndex().getTableName(),item.getID(),sortMap);
      }
      reqCommunityMappings=true;
    }
 else     if (item.isWithdrawn()) {
      if (!dao.updateIndex(BrowseIndex.getWithdrawnBrowseIndex().getTableName(),item.getID(),sortMap)) {
        removeIndex(item.getID(),BrowseIndex.getItemBrowseIndex().getTableName());
        dao.insertIndex(BrowseIndex.getWithdrawnBrowseIndex().getTableName(),item.getID(),sortMap);
      }
    }
 else {
      removeIndex(item.getID(),BrowseIndex.getItemBrowseIndex().getTableName());
      removeIndex(item.getID(),BrowseIndex.getWithdrawnBrowseIndex().getTableName());
    }
    if (reqCommunityMappings) {
      dao.updateCommunityMappings(item.getID());
    }
 else {
      dao.deleteCommunityMappings(item.getID());
    }
    for (int i=0; i < bis.length; i++) {
      log.debug("String_Node_Str" + item.getID() + "String_Node_Str"+ bis[i].getTableName());
      if (bis[i].isMetadataIndex()) {
        boolean itemMapped=false;
        if (item.isArchived() && !item.isWithdrawn()) {
          for (int mdIdx=0; mdIdx < bis[i].getMetadataCount(); mdIdx++) {
            String[] md=bis[i].getMdBits(mdIdx);
            DCValue[] values=item.getMetadata(md[0],md[1],md[2],Item.ANY);
            if (values != null) {
              for (int x=0; x < values.length; x++) {
                if (StringUtils.isEmpty(values[x].value)) {
                  log.error("String_Node_Str" + item.getID() + "String_Node_Str"+ values[x].schema+ "String_Node_Str"+ values[x].element+ (values[x].qualifier == null ? "String_Node_Str" : "String_Node_Str" + values[x].qualifier));
                }
 else {
                  String nVal=OrderFormat.makeSortString(values[x].value,values[x].language,bis[i].getDataType());
                  int distinctID=dao.getDistinctID(bis[i].getDistinctTableName(),values[x].value,nVal);
                  if (!dao.updateDistinctMapping(bis[i].getMapTableName(),item.getID(),distinctID))                   dao.createDistinctMapping(bis[i].getMapTableName(),item.getID(),distinctID);
                  itemMapped=true;
                }
              }
            }
          }
        }
        if (!itemMapped)         removeIndex(item.getID(),bis[i].getMapTableName());
      }
    }
  }
 catch (  SQLException e) {
    log.error("String_Node_Str",e);
    throw new BrowseException(e);
  }
}

Fixed version (ground truth):
/** 
 * Index the given item
 * @param item  the item to index
 * @throws BrowseException
 */
private void indexItem(ItemMetadataProxy item) throws BrowseException {
  Map<String,String> itemMDMap=new HashMap<String,String>();
  try {
    boolean reqCommunityMappings=false;
    Map<Integer,String> sortMap=getSortValues(item,itemMDMap);
    if (item.isArchived() && !item.isWithdrawn()) {
      if (!dao.updateIndex(BrowseIndex.getItemBrowseIndex().getTableName(),item.getID(),sortMap)) {
        removeIndex(item.getID(),BrowseIndex.getWithdrawnBrowseIndex().getTableName());
        dao.insertIndex(BrowseIndex.getItemBrowseIndex().getTableName(),item.getID(),sortMap);
      }
      reqCommunityMappings=true;
    }
 else     if (item.isWithdrawn()) {
      if (!dao.updateIndex(BrowseIndex.getWithdrawnBrowseIndex().getTableName(),item.getID(),sortMap)) {
        removeIndex(item.getID(),BrowseIndex.getItemBrowseIndex().getTableName());
        dao.insertIndex(BrowseIndex.getWithdrawnBrowseIndex().getTableName(),item.getID(),sortMap);
      }
    }
 else {
      removeIndex(item.getID(),BrowseIndex.getItemBrowseIndex().getTableName());
      removeIndex(item.getID(),BrowseIndex.getWithdrawnBrowseIndex().getTableName());
    }
    if (reqCommunityMappings) {
      dao.updateCommunityMappings(item.getID());
    }
 else {
      dao.deleteCommunityMappings(item.getID());
    }
    for (int i=0; i < bis.length; i++) {
      log.debug("String_Node_Str" + item.getID() + "String_Node_Str"+ bis[i].getTableName());
      if (bis[i].isMetadataIndex()) {
        Set<Integer> distIDSet=new HashSet<Integer>();
        if (item.isArchived() && !item.isWithdrawn()) {
          for (int mdIdx=0; mdIdx < bis[i].getMetadataCount(); mdIdx++) {
            String[] md=bis[i].getMdBits(mdIdx);
            DCValue[] values=item.getMetadata(md[0],md[1],md[2],Item.ANY);
            if (values != null) {
              for (int x=0; x < values.length; x++) {
                if (StringUtils.isEmpty(values[x].value)) {
                  log.error("String_Node_Str" + item.getID() + "String_Node_Str"+ values[x].schema+ "String_Node_Str"+ values[x].element+ (values[x].qualifier == null ? "String_Node_Str" : "String_Node_Str" + values[x].qualifier));
                }
 else {
                  String nVal=OrderFormat.makeSortString(values[x].value,values[x].language,bis[i].getDataType());
                  distIDSet.add(dao.getDistinctID(bis[i].getDistinctTableName(),values[x].value,nVal));
                }
              }
            }
          }
        }
        if (distIDSet.isEmpty()) {
          removeIndex(item.getID(),bis[i].getMapTableName());
        }
 else {
          int[] distIDarr=new int[distIDSet.size()];
          int didx=0;
          for (          Integer distID : distIDSet) {
            distIDarr[didx++]=distID;
          }
          dao.updateDistinctMappings(bis[i].getMapTableName(),item.getID(),distIDarr);
        }
      }
    }
  }
 catch (  SQLException e) {
    log.error("String_Node_Str",e);
    throw new BrowseException(e);
  }
}