Program: 174742
Project: 174742
Buggy source:
/** 
 * Wrap up search results as   {@link TopicInfo} instances
 * @param finalResults ResultSet
 * @param paging PagingRequest
 * @return PagingResults<TopicInfo>
 */
protected PagingResults<TopicInfo> wrap(final ResultSet finalResults,PagingRequest paging){
  int maxItems=paging.getMaxItems();
  Comparator<TopicInfo> lastPostDesc=new Comparator<TopicInfo>(){
    @Override public int compare(    TopicInfo t1,    TopicInfo t2){
      Date t1LastPostDate=t1.getCreatedAt();
      if (discussionService.getMostRecentPost(t1) != null) {
        t1LastPostDate=discussionService.getMostRecentPost(t1).getCreatedAt();
      }
      Date t2LastPostDate=t2.getCreatedAt();
      if (discussionService.getMostRecentPost(t2) != null) {
        t2LastPostDate=discussionService.getMostRecentPost(t2).getCreatedAt();
      }
      return t2LastPostDate.compareTo(t1LastPostDate);
    }
  }
;
  final Set<TopicInfo> topics=new TreeSet<TopicInfo>(lastPostDesc);
  for (  ResultSetRow row : finalResults) {
    Pair<TopicInfo,PostInfo> pair=discussionService.getForNodeRef(row.getNodeRef());
    TopicInfo topic=pair.getFirst();
    if (topic != null) {
      String path=nodeService.getPath(topic.getNodeRef()).toDisplayPath(nodeService,permissionService);
      String site=path.split("String_Node_Str")[3];
      TopicInfoImpl tii=(TopicInfoImpl)topic;
      tii.setShortSiteName(site);
      topics.add(tii);
      if (topics.size() >= maxItems) {
        break;
      }
    }
  }
  return new PagingResults<TopicInfo>(){
    @Override public boolean hasMoreItems(){
      try {
        return finalResults.hasMore();
      }
 catch (      UnsupportedOperationException e) {
        return false;
      }
    }
    @Override public Pair<Integer,Integer> getTotalResultCount(){
      int skipCount=0;
      int itemsRemainingAfterThisPage=0;
      try {
        skipCount=finalResults.getStart();
      }
 catch (      UnsupportedOperationException e) {
      }
      try {
        itemsRemainingAfterThisPage=finalResults.length();
      }
 catch (      UnsupportedOperationException e) {
      }
      final int totalItemsInUnpagedResultSet=skipCount + itemsRemainingAfterThisPage;
      return new Pair<Integer,Integer>(totalItemsInUnpagedResultSet,totalItemsInUnpagedResultSet);
    }
    @Override public List<TopicInfo> getPage(){
      return new ArrayList<TopicInfo>(topics);
    }
    @Override public String getQueryExecutionId(){
      return null;
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Wrap up search results as   {@link TopicInfo} instances
 * @param finalResults ResultSet
 * @param paging PagingRequest
 */
protected PagingResults<TopicInfo> wrap(final ResultSet finalResults,PagingRequest paging){
  int maxItems=paging.getMaxItems();
  Comparator<TopicInfo> lastPostDesc=new Comparator<TopicInfo>(){
    @Override public int compare(    TopicInfo t1,    TopicInfo t2){
      Date t1LastPostDate=t1.getCreatedAt();
      if (discussionService.getMostRecentPost(t1) != null) {
        t1LastPostDate=discussionService.getMostRecentPost(t1).getCreatedAt();
      }
      Date t2LastPostDate=t2.getCreatedAt();
      if (discussionService.getMostRecentPost(t2) != null) {
        t2LastPostDate=discussionService.getMostRecentPost(t2).getCreatedAt();
      }
      return t2LastPostDate.compareTo(t1LastPostDate);
    }
  }
;
  final Set<TopicInfo> topics=new TreeSet<TopicInfo>(lastPostDesc);
  for (  ResultSetRow row : finalResults) {
    Pair<TopicInfo,PostInfo> pair=discussionService.getForNodeRef(row.getNodeRef());
    TopicInfo topic=pair.getFirst();
    if (topic != null) {
      String path=nodeService.getPath(topic.getNodeRef()).toDisplayPath(nodeService,permissionService);
      String site=path.split("String_Node_Str")[3];
      TopicInfoImpl tii=(TopicInfoImpl)topic;
      tii.setShortSiteName(site);
      topics.add(tii);
      if (topics.size() >= maxItems) {
        break;
      }
    }
  }
  return new PagingResults<TopicInfo>(){
    @Override public boolean hasMoreItems(){
      try {
        return finalResults.hasMore();
      }
 catch (      UnsupportedOperationException e) {
        return false;
      }
    }
    @Override public Pair<Integer,Integer> getTotalResultCount(){
      int skipCount=0;
      int itemsRemainingAfterThisPage=0;
      try {
        skipCount=finalResults.getStart();
      }
 catch (      UnsupportedOperationException e) {
      }
      try {
        itemsRemainingAfterThisPage=finalResults.length();
      }
 catch (      UnsupportedOperationException e) {
      }
      final int totalItemsInUnpagedResultSet=skipCount + itemsRemainingAfterThisPage;
      return new Pair<Integer,Integer>(totalItemsInUnpagedResultSet,totalItemsInUnpagedResultSet);
    }
    @Override public List<TopicInfo> getPage(){
      return new ArrayList<TopicInfo>(topics);
    }
    @Override public String getQueryExecutionId(){
      return null;
    }
  }
;
}