Program: 63425
Project: 63425
Buggy source:
private PageableCollection populatePagedCollectionLinks(Map<String,Object> queryParams,UriInfo uriInfo,PageableCollection resultCollection){
  final ItemLinksBuilder itemLinksBuilder=new ItemLinksBuilder();
  int limit=Integer.parseInt((String)queryParams.get(QueryParameters.JPARS_PAGING_LIMIT));
  int offset=Integer.parseInt((String)queryParams.get(QueryParameters.JPARS_PAGING_OFFSET));
  String nextOffset;
  String prevOffset;
  if (limit > offset) {
    nextOffset=String.valueOf(limit);
    prevOffset=NO_PREVIOUS_CHUNK;
  }
 else {
    nextOffset=String.valueOf(limit + offset);
    prevOffset=String.valueOf(offset - limit);
  }
  UriBuilder uriBuilder;
  if (resultCollection.getCount() != null) {
    int actualCount=resultCollection.getCount();
    if (actualCount >= limit) {
      uriBuilder=UriBuilder.fromUri(uriInfo.getRequestUri());
      uriBuilder.replaceQueryParam(QueryParameters.JPARS_PAGING_OFFSET,nextOffset);
      itemLinksBuilder.addNext(uriBuilder.build().toString());
      resultCollection.setHasMore(true);
    }
 else {
      resultCollection.setHasMore(false);
    }
  }
  if (!NO_PREVIOUS_CHUNK.equals(prevOffset)) {
    uriBuilder=UriBuilder.fromUri(uriInfo.getRequestUri());
    uriBuilder.replaceQueryParam(QueryParameters.JPARS_PAGING_OFFSET,prevOffset);
    itemLinksBuilder.addPrev(uriBuilder.build().toString());
  }
  itemLinksBuilder.addSelf(uriInfo.getRequestUri().toString());
  resultCollection.setLinks(itemLinksBuilder.build().getLinks());
  resultCollection.setOffset(offset);
  resultCollection.setLimit(limit);
  return resultCollection;
}

Fixed version (ground truth):
private PageableCollection populatePagedCollectionLinks(Map<String,Object> queryParams,UriInfo uriInfo,PageableCollection resultCollection){
  final ItemLinksBuilder itemLinksBuilder=new ItemLinksBuilder();
  final int limit=Integer.parseInt((String)queryParams.get(QueryParameters.JPARS_PAGING_LIMIT));
  final int offset=Integer.parseInt((String)queryParams.get(QueryParameters.JPARS_PAGING_OFFSET));
  final UriBuilder uriBuilder=UriBuilder.fromUri(uriInfo.getRequestUri());
  if (resultCollection.getItems() != null) {
    final int actualCount=resultCollection.getItems().size();
    if (actualCount > limit) {
      resultCollection.getItems().remove(actualCount - 1);
      resultCollection.setCount(actualCount - 1);
      uriBuilder.replaceQueryParam(QueryParameters.JPARS_PAGING_OFFSET,String.valueOf(limit + offset));
      itemLinksBuilder.addNext(uriBuilder.build().toString());
      resultCollection.setHasMore(true);
    }
 else {
      resultCollection.setHasMore(false);
      resultCollection.setCount(actualCount);
    }
  }
 else {
    resultCollection.setCount(0);
  }
  if (offset != 0) {
    if (offset > limit) {
      uriBuilder.replaceQueryParam(QueryParameters.JPARS_PAGING_OFFSET,String.valueOf(offset - limit));
    }
 else {
      uriBuilder.replaceQueryParam(QueryParameters.JPARS_PAGING_OFFSET,"String_Node_Str");
    }
    itemLinksBuilder.addPrev(uriBuilder.build().toString());
  }
  itemLinksBuilder.addSelf(uriInfo.getRequestUri().toString());
  resultCollection.setLinks(itemLinksBuilder.build().getLinks());
  resultCollection.setOffset(offset);
  resultCollection.setLimit(limit);
  return resultCollection;
}