Program: 12983
Project: 12983
Buggy source:
/** 
 * @see org.overlord.sramp.ui.client.shared.services.IArtifactSearchService#search(org.overlord.sramp.ui.client.shared.beans.ArtifactFilterBean,java.lang.String,int)
 */
@Override public ArtifactResultSetBean search(ArtifactFilterBean filters,String searchText,int page) throws SrampUiException {
  int pageSize=20;
  try {
    ArtifactResultSetBean rval=new ArtifactResultSetBean();
    int req_startIndex=(page - 1) * pageSize;
    SrampClientQuery query=null;
    if (searchText != null && searchText.startsWith("String_Node_Str")) {
      query=clientAccessor.getClient().buildQuery(searchText);
    }
 else {
      query=createQuery(filters,searchText);
    }
    QueryResultSet resultSet=query.startIndex(req_startIndex).orderBy("String_Node_Str").ascending().count(pageSize + 1).query();
    ArrayList<ArtifactSummaryBean> artifacts=new ArrayList<ArtifactSummaryBean>();
    for (    ArtifactSummary artifactSummary : resultSet) {
      ArtifactSummaryBean bean=new ArtifactSummaryBean();
      ArtifactType artifactType=artifactSummary.getType();
      bean.setModel(artifactType.getArtifactType().getModel());
      bean.setType(artifactType.getType());
      bean.setRawType(artifactType.getArtifactType().getType());
      bean.setUuid(artifactSummary.getUuid());
      bean.setName(artifactSummary.getName());
      bean.setDescription(artifactSummary.getDescription());
      bean.setCreatedBy(artifactSummary.getCreatedBy());
      bean.setCreatedOn(artifactSummary.getCreatedTimestamp());
      bean.setUpdatedOn(artifactSummary.getLastModifiedTimestamp());
      bean.setDerived(artifactType.getArtifactType().isDerived());
      artifacts.add(bean);
    }
    boolean hasMorePages=false;
    if (artifacts.size() > pageSize) {
      artifacts.remove(artifacts.get(artifacts.size() - 1));
      hasMorePages=true;
    }
    if (resultSet.getTotalResults() != -1) {
      rval.setItemsPerPage(pageSize);
      rval.setStartIndex(resultSet.getStartIndex());
      rval.setTotalResults(resultSet.getTotalResults());
    }
 else {
      rval.setItemsPerPage(pageSize);
      rval.setTotalResults(hasMorePages ? pageSize + 1 : artifacts.size());
      rval.setStartIndex(req_startIndex);
    }
    rval.setArtifacts(artifacts);
    return rval;
  }
 catch (  SrampClientException e) {
    throw new SrampUiException(e.getMessage());
  }
catch (  SrampAtomException e) {
    throw new SrampUiException(e.getMessage());
  }
}

Fixed version (ground truth):
/** 
 * @see org.overlord.sramp.ui.client.shared.services.IArtifactSearchService#search(org.overlord.sramp.ui.client.shared.beans.ArtifactFilterBean,java.lang.String,int)
 */
@Override public ArtifactResultSetBean search(ArtifactFilterBean filters,String searchText,int page) throws SrampUiException {
  int pageSize=20;
  try {
    ArtifactResultSetBean rval=new ArtifactResultSetBean();
    int req_startIndex=(page - 1) * pageSize;
    SrampClientQuery query=null;
    if (searchText != null && searchText.startsWith("String_Node_Str")) {
      query=clientAccessor.getClient().buildQuery(searchText);
    }
 else {
      query=createQuery(filters,searchText);
    }
    QueryResultSet resultSet=query.startIndex(req_startIndex).orderBy("String_Node_Str").ascending().count(pageSize + 1).query();
    ArrayList<ArtifactSummaryBean> artifacts=new ArrayList<ArtifactSummaryBean>();
    for (    ArtifactSummary artifactSummary : resultSet) {
      ArtifactSummaryBean bean=new ArtifactSummaryBean();
      ArtifactType artifactType=artifactSummary.getType();
      bean.setModel(artifactType.getArtifactType().getModel());
      bean.setType(artifactType.getType());
      bean.setRawType(artifactType.getArtifactType().getType());
      bean.setUuid(artifactSummary.getUuid());
      bean.setName(artifactSummary.getName());
      bean.setDescription(artifactSummary.getDescription());
      bean.setCreatedBy(artifactSummary.getCreatedBy());
      bean.setCreatedOn(artifactSummary.getCreatedTimestamp());
      bean.setUpdatedOn(artifactSummary.getLastModifiedTimestamp());
      bean.setDerived(artifactType.isDerived());
      artifacts.add(bean);
    }
    boolean hasMorePages=false;
    if (artifacts.size() > pageSize) {
      artifacts.remove(artifacts.get(artifacts.size() - 1));
      hasMorePages=true;
    }
    if (resultSet.getTotalResults() != -1) {
      rval.setItemsPerPage(pageSize);
      rval.setStartIndex(resultSet.getStartIndex());
      rval.setTotalResults(resultSet.getTotalResults());
    }
 else {
      rval.setItemsPerPage(pageSize);
      rval.setTotalResults(hasMorePages ? pageSize + 1 : artifacts.size());
      rval.setStartIndex(req_startIndex);
    }
    rval.setArtifacts(artifacts);
    return rval;
  }
 catch (  SrampClientException e) {
    throw new SrampUiException(e.getMessage());
  }
catch (  SrampAtomException e) {
    throw new SrampUiException(e.getMessage());
  }
}