Program: 3480
Project: 3480
Buggy source:
/** 
 * Browse the archive by the full item browse mechanism.  This produces a BrowseInfo object which contains full BrowseItem objects as its result set.
 * @param bs		the scope of the browse
 * @return			the results of the browse
 * @throws BrowseException
 */
private BrowseInfo browseByItem(BrowserScope bs) throws BrowseException {
  log.info(LogManager.getHeader(context,"String_Node_Str","String_Node_Str"));
  try {
    dao.setTable(browseIndex.getTableName());
    dao.setAscending(scope.isAscending());
    String focusValue=null;
    String rawFocusValue=null;
    String focusField=browseIndex.getSortField(scope.isSecondLevel());
    if (scope.hasJumpToItem() || scope.hasJumpToValue() || scope.hasStartsWith()) {
      focusValue=getJumpToValue();
      rawFocusValue=focusValue;
      focusValue=normalizeJumpToValue(focusValue);
      if (scope.hasStartsWith()) {
        if (browseIndex.isDate()) {
          focusValue=focusValue + "String_Node_Str";
        }
      }
      log.debug("String_Node_Str" + focusValue);
      if (scope.getSortBy() > 0) {
        focusField="String_Node_Str" + Integer.toString(scope.getSortBy());
      }
      dao.setJumpToField(focusField);
      dao.setJumpToValue(focusValue);
    }
    String value=null;
    String rawValue=null;
    if (scope.hasFilterValue() && scope.isSecondLevel()) {
      value=scope.getFilterValue();
      rawValue=value;
      value=OrderFormat.makeSortString(value,scope.getFilterValueLang(),scope.getBrowseIndex().getDataType());
      dao.setFilterValueField("String_Node_Str");
      dao.setFilterValue(value);
      dao.setFilterValuePartial(scope.getFilterValuePartial());
      dao.setFilterMappingTables(browseIndex.getTableName(false,false,true,false),browseIndex.getTableName(false,false,false,true));
    }
    if (scope.inCollection() || scope.inCommunity()) {
      if (scope.inCollection()) {
        Collection col=(Collection)scope.getBrowseContainer();
        dao.setContainerTable("String_Node_Str");
        dao.setContainerIDField("String_Node_Str");
        dao.setContainerID(col.getID());
      }
 else       if (scope.inCommunity()) {
        Community com=(Community)scope.getBrowseContainer();
        dao.setContainerTable("String_Node_Str");
        dao.setContainerIDField("String_Node_Str");
        dao.setContainerID(com.getID());
      }
    }
    String orderBy=browseIndex.getSortField(scope.isSecondLevel());
    if (scope.getSortBy() > 0) {
      orderBy="String_Node_Str" + Integer.toString(scope.getSortBy());
    }
    dao.setOrderField(orderBy);
    dao.setLimit(scope.getResultsPerPage() + 1);
    List results=dao.doQuery();
    boolean showLast=false;
    if (results.size() == 0) {
      showLast=true;
    }
    BrowseItem next=null;
    int lastIndex=results.size() - 1;
    if (lastIndex >= scope.getResultsPerPage()) {
      next=(BrowseItem)results.get(lastIndex);
      results.remove(lastIndex);
    }
    BrowseItem prev=null;
    if (scope.hasJumpToItem() || scope.hasJumpToValue() || scope.hasStartsWith()) {
      int prevID=-1;
      if (showLast) {
        prevID=getPreviousPageID(results);
      }
 else {
        prevID=getPreviousPageID(null);
      }
      if (prevID != -1) {
        if (bs.getBrowseIndex() == BrowseIndex.getWithdrawnBrowseIndex())         prev=new BrowseItem(context,prevID,false,true);
 else         prev=new BrowseItem(context,prevID,true,false);
      }
    }
    int offset=0;
    int total=getTotalResults();
    int position=-1;
    if (total > 0) {
      if (showLast) {
        position=total - scope.getResultsPerPage();
        if (position < 0)         position=0;
      }
 else {
        position=getPosition(false);
      }
    }
    BrowseInfo browseInfo=new BrowseInfo(results,position,total,offset);
    if (next != null) {
      browseInfo.setNextItem(next.getID());
    }
    if (prev != null) {
      browseInfo.setPrevItem(prev.getID());
    }
    browseInfo.setBrowseIndex(browseIndex);
    browseInfo.setSortOption(scope.getSortOption());
    browseInfo.setAscending(scope.isAscending());
    browseInfo.setBrowseLevel(scope.getBrowseLevel());
    browseInfo.setValue(rawValue);
    browseInfo.setFocus(rawFocusValue);
    if (scope.hasJumpToItem()) {
      browseInfo.setFocusItem(scope.getJumpToItem());
    }
    browseInfo.setStartsWith(scope.hasStartsWith());
    if (scope.inCollection() || scope.inCommunity()) {
      browseInfo.setBrowseContainer(scope.getBrowseContainer());
    }
    browseInfo.setResultsPerPage(scope.getResultsPerPage());
    browseInfo.setEtAl(scope.getEtAl());
    return browseInfo;
  }
 catch (  SQLException e) {
    log.error("String_Node_Str",e);
    throw new BrowseException(e);
  }
}

Fixed version (ground truth):
/** 
 * Browse the archive by the full item browse mechanism.  This produces a BrowseInfo object which contains full BrowseItem objects as its result set.
 * @param bs        the scope of the browse
 * @return          the results of the browse
 * @throws BrowseException
 */
private BrowseInfo browseByItem(BrowserScope bs) throws BrowseException {
  log.info(LogManager.getHeader(context,"String_Node_Str","String_Node_Str"));
  try {
    dao.setTable(browseIndex.getTableName());
    dao.setAscending(scope.isAscending());
    String rawValue=null;
    if (scope.hasFilterValue() && scope.isSecondLevel()) {
      String value=scope.getFilterValue();
      rawValue=value;
      value=OrderFormat.makeSortString(value,scope.getFilterValueLang(),scope.getBrowseIndex().getDataType());
      dao.setFilterValueField("String_Node_Str");
      dao.setFilterValue(value);
      dao.setFilterValuePartial(scope.getFilterValuePartial());
      dao.setFilterMappingTables(browseIndex.getDistinctTableName(),browseIndex.getMapTableName());
    }
    if (scope.inCollection() || scope.inCommunity()) {
      if (scope.inCollection()) {
        Collection col=(Collection)scope.getBrowseContainer();
        dao.setContainerTable("String_Node_Str");
        dao.setContainerIDField("String_Node_Str");
        dao.setContainerID(col.getID());
      }
 else       if (scope.inCommunity()) {
        Community com=(Community)scope.getBrowseContainer();
        dao.setContainerTable("String_Node_Str");
        dao.setContainerIDField("String_Node_Str");
        dao.setContainerID(com.getID());
      }
    }
    int offset=scope.getOffset();
    String rawFocusValue=null;
    if (offset < 1 && (scope.hasJumpToItem() || scope.hasJumpToValue() || scope.hasStartsWith())) {
      rawFocusValue=getJumpToValue();
      String focusValue=normalizeJumpToValue(rawFocusValue);
      if (scope.hasStartsWith()) {
        if (browseIndex.isDate()) {
          focusValue=focusValue + "String_Node_Str";
        }
      }
      log.debug("String_Node_Str" + focusValue);
      String focusField=browseIndex.getSortField(scope.isSecondLevel());
      if (scope.getSortBy() > 0) {
        focusField="String_Node_Str" + Integer.toString(scope.getSortBy());
      }
      offset=getOffsetForValue(focusValue);
    }
    dao.setOffset(offset);
    String orderBy=browseIndex.getSortField(scope.isSecondLevel());
    if (scope.getSortBy() > 0) {
      orderBy="String_Node_Str" + Integer.toString(scope.getSortBy());
    }
    dao.setOrderField(orderBy);
    dao.setLimit(scope.getResultsPerPage());
    List results=dao.doQuery();
    int total=getTotalResults();
    if (results.size() == 0) {
      offset=total - scope.getResultsPerPage();
      if (offset < 0)       offset=0;
      dao.setOffset(offset);
      results=dao.doQuery();
      total=getTotalResults();
    }
    BrowseInfo browseInfo=new BrowseInfo(results,offset,total,offset);
    if (offset + scope.getResultsPerPage() < total) {
      browseInfo.setNextOffset(offset + scope.getResultsPerPage());
    }
    if (offset - scope.getResultsPerPage() > -1) {
      browseInfo.setPrevOffset(offset - scope.getResultsPerPage());
    }
    browseInfo.setBrowseIndex(browseIndex);
    browseInfo.setSortOption(scope.getSortOption());
    browseInfo.setAscending(scope.isAscending());
    browseInfo.setBrowseLevel(scope.getBrowseLevel());
    browseInfo.setValue(rawValue);
    browseInfo.setFocus(rawFocusValue);
    if (scope.hasJumpToItem()) {
      browseInfo.setFocusItem(scope.getJumpToItem());
    }
    browseInfo.setStartsWith(scope.hasStartsWith());
    if (scope.inCollection() || scope.inCommunity()) {
      browseInfo.setBrowseContainer(scope.getBrowseContainer());
    }
    browseInfo.setResultsPerPage(scope.getResultsPerPage());
    browseInfo.setEtAl(scope.getEtAl());
    return browseInfo;
  }
 catch (  SQLException e) {
    log.error("String_Node_Str",e);
    throw new BrowseException(e);
  }
}