Program: 44625
Project: 44625
Buggy source:
/** 
 * Every search returns the total number of matched objects even if the objects we ask to render back in the result set are less than the total matched We need the total number of matched objects in order to build the PagedDataModel in the following lines. The PagedDataModel supports the lazy loading of results and their presentation in pages of a few ones each time so that very large results sets can be presented to the user  without consuming all the system memory. The PagedDataModel will automatically set up the result set in each page fetch in order to lazy load pages of content objects as the user iterates  through the pages of returned content objects
 */
public int searchForContentWithPagedResults(ContentObjectCriteria contentObjectCriteria,boolean useDefaultRenderProperties,String locale,int pageSize) throws CmsException {
  searchResultSetSize=0;
  localContentObjectCriteria=CmsCriteriaFactory.newContentObjectCriteria();
  contentObjectCriteria.copyTo(localContentObjectCriteria);
  if (useDefaultRenderProperties)   setDefaultRenderPropertiesToContentObjectCriteria(localContentObjectCriteria,locale);
  CmsOutcome<ContentObject> cmsOutcome=contentService.searchContentObjects(localContentObjectCriteria,ResourceRepresentationType.CONTENT_OBJECT_LIST);
  if (cmsOutcome.getCount() > 0) {
    if (returnedContentObjects != null) {
      returnedContentObjects.reset();
      contentObjectSelection.clearAllSelectedContentObjects_UIAction();
    }
 else     returnedContentObjects=new ContentObjectDataModel(pageSize);
    searchResultSetSize=(int)cmsOutcome.getCount();
    List<ContentObject> cmsOutcomeRowList=cmsOutcome.getResults();
    List<ContentObjectUIWrapper> wrappedContentObjects=new ArrayList<ContentObjectUIWrapper>();
    for (    ContentObject contentObject : cmsOutcomeRowList) {
      wrappedContentObjects.add(contentObjectUIWrapperFactory.getInstance(contentObject));
    }
    DataPage<ContentObjectUIWrapper> dataPage=new DataPage<ContentObjectUIWrapper>(getSearchResultSetSize(),0,wrappedContentObjects);
    returnedContentObjects.setPage(dataPage);
  }
 else {
    returnedContentObjects=null;
    contentObjectSelection.clearAllSelectedContentObjects_UIAction();
  }
  return searchResultSetSize;
}

Fixed version (ground truth):
/** 
 * Every search returns the total number of matched objects even if the objects we ask to render back in the result set are less than the total matched We need the total number of matched objects in order to build the PagedDataModel in the following lines. The PagedDataModel supports the lazy loading of results and their presentation in pages of a few ones each time so that very large results sets can be presented to the user  without consuming all the system memory. The PagedDataModel will automatically set up the result set in each page fetch in order to lazy load pages of content objects as the user iterates  through the pages of returned content objects
 */
public int searchForContentWithPagedResults(ContentObjectCriteria contentObjectCriteria,boolean useDefaultRenderProperties,String locale,int pageSize) throws CmsException {
  searchResultSetSize=0;
  localContentObjectCriteria=CmsCriteriaFactory.newContentObjectCriteria();
  contentObjectCriteria.copyTo(localContentObjectCriteria);
  if (useDefaultRenderProperties)   setDefaultRenderPropertiesToContentObjectCriteria(localContentObjectCriteria,locale);
  CmsOutcome<ContentObject> cmsOutcome=contentService.searchContentObjects(localContentObjectCriteria,ResourceRepresentationType.CONTENT_OBJECT_LIST);
  if (cmsOutcome.getCount() > 0) {
    returnedContentObjects=new ContentObjectDataModel(pageSize);
    searchResultSetSize=(int)cmsOutcome.getCount();
    List<ContentObject> cmsOutcomeRowList=cmsOutcome.getResults();
    List<ContentObjectUIWrapper> wrappedContentObjects=new ArrayList<ContentObjectUIWrapper>();
    for (    ContentObject contentObject : cmsOutcomeRowList) {
      wrappedContentObjects.add(contentObjectUIWrapperFactory.getInstance(contentObject));
    }
    DataPage<ContentObjectUIWrapper> dataPage=new DataPage<ContentObjectUIWrapper>(getSearchResultSetSize(),0,wrappedContentObjects);
    returnedContentObjects.setPage(dataPage);
  }
 else {
    returnedContentObjects=null;
    contentObjectSelection.clearAllSelectedContentObjects_UIAction();
  }
  return searchResultSetSize;
}