Program: 52204
Project: 52204
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()) {
        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 && values.length > 0) {
              int minConfidence=MetadataAuthorityManager.getManager().getMinConfidence(values[0].schema,values[0].element,values[0].qualifier);
              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 {
                  if (bis[i].isAuthorityIndex() && (values[x].authority == null || values[x].confidence < minConfidence)) {
                    log.debug("String_Node_Str" + item.getID() + "String_Node_Str"+ values[x].schema+ "String_Node_Str"+ values[x].element+ "String_Node_Str"+ values[x].qualifier+ "String_Node_Str"+ values[x].value+ "String_Node_Str"+ values[x].authority+ "String_Node_Str"+ values[x].confidence+ "String_Node_Str");
                    break;
                  }
                  if (values[x].authority != null && values[x].confidence >= minConfidence) {
                    boolean isValueVariants=false;
                    List<String> variants=ChoiceAuthorityManager.getManager().getVariants(values[x].schema,values[x].element,values[x].qualifier,values[x].authority,values[x].language);
                    if (variants != null) {
                      for (                      String var : variants) {
                        String nVal=OrderFormat.makeSortString(var,values[x].language,bis[i].getDataType());
                        distIDSet.add(dao.getDistinctID(bis[i].getDistinctTableName(),var,values[x].authority,nVal));
                        if (var.equals(values[x].value)) {
                          isValueVariants=true;
                        }
                      }
                    }
                    if (!isValueVariants) {
                      String nVal=OrderFormat.makeSortString(values[x].value,values[x].language,bis[i].getDataType());
                      distIDSet.add(dao.getDistinctID(bis[i].getDistinctTableName(),values[x].value,values[x].authority,nVal));
                    }
                  }
 else {
                    String nVal=OrderFormat.makeSortString(values[x].value,values[x].language,bis[i].getDataType());
                    distIDSet.add(dao.getDistinctID(bis[i].getDistinctTableName(),values[x].value,null,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);
  }
}

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 && values.length > 0) {
              int minConfidence=MetadataAuthorityManager.getManager().getMinConfidence(values[0].schema,values[0].element,values[0].qualifier);
              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 {
                  if (bis[i].isAuthorityIndex() && (values[x].authority == null || values[x].confidence < minConfidence)) {
                    log.debug("String_Node_Str" + item.getID() + "String_Node_Str"+ values[x].schema+ "String_Node_Str"+ values[x].element+ "String_Node_Str"+ values[x].qualifier+ "String_Node_Str"+ values[x].value+ "String_Node_Str"+ values[x].authority+ "String_Node_Str"+ values[x].confidence+ "String_Node_Str");
                    continue;
                  }
                  if (values[x].authority != null && values[x].confidence >= minConfidence) {
                    boolean isValueVariants=false;
                    List<String> variants=ChoiceAuthorityManager.getManager().getVariants(values[x].schema,values[x].element,values[x].qualifier,values[x].authority,values[x].language);
                    if (variants != null) {
                      for (                      String var : variants) {
                        String nVal=OrderFormat.makeSortString(var,values[x].language,bis[i].getDataType());
                        distIDSet.add(dao.getDistinctID(bis[i].getDistinctTableName(),var,values[x].authority,nVal));
                        if (var.equals(values[x].value)) {
                          isValueVariants=true;
                        }
                      }
                    }
                    if (!isValueVariants) {
                      String nVal=OrderFormat.makeSortString(values[x].value,values[x].language,bis[i].getDataType());
                      distIDSet.add(dao.getDistinctID(bis[i].getDistinctTableName(),values[x].value,values[x].authority,nVal));
                    }
                  }
 else {
                    String nVal=OrderFormat.makeSortString(values[x].value,values[x].language,bis[i].getDataType());
                    distIDSet.add(dao.getDistinctID(bis[i].getDistinctTableName(),values[x].value,null,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);
  }
}