Program: 52467
Project: 52467
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(scope.inCommunity(),scope.inCollection()));
    dao.setAscending(scope.isAscending());
    String focusValue=null;
    String rawFocusValue=null;
    String focusField=browseIndex.getSortField();
    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());
    }
    if (scope.inCollection() || scope.inCommunity()) {
      if (scope.inCollection()) {
        Collection col=(Collection)scope.getBrowseContainer();
        dao.setContainerIDField("String_Node_Str");
        dao.setContainerID(col.getID());
      }
 else       if (scope.inCommunity()) {
        Community com=(Community)scope.getBrowseContainer();
        dao.setContainerIDField("String_Node_Str");
        dao.setContainerID(com.getID());
      }
    }
    String orderBy=browseIndex.getSortField();
    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(scope.inCommunity(),scope.inCollection()));
    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());
    }
    if (scope.inCollection() || scope.inCommunity()) {
      if (scope.inCollection()) {
        Collection col=(Collection)scope.getBrowseContainer();
        dao.setContainerIDField("String_Node_Str");
        dao.setContainerID(col.getID());
      }
 else       if (scope.inCommunity()) {
        Community com=(Community)scope.getBrowseContainer();
        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);
  }
}