Program: 90010
Project: 90010
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public Page<JobSearchResult> findJobs(final String id,final String jobName,final String user,final Set<JobStatus> statuses,final Set<String> tags,final String clusterName,final String clusterId,final String commandName,final String commandId,final Date minStarted,final Date maxStarted,final Date minFinished,final Date maxFinished,@NotNull final Pageable page){
  log.debug("String_Node_Str");
  final CriteriaBuilder cb=this.entityManager.getCriteriaBuilder();
  final CriteriaQuery<Long> countQuery=cb.createQuery(Long.class);
  final Root<JobEntity> root=countQuery.from(JobEntity.class);
  final Predicate whereClause=JpaJobSpecs.getFindPredicate(root,cb,id,jobName,user,statuses,tags,clusterName,clusterId,commandName,commandId,minStarted,maxStarted,minFinished,maxFinished);
  countQuery.select(cb.count(root)).where(whereClause);
  final Long count=this.entityManager.createQuery(countQuery).getSingleResult();
  if (count > 0) {
    final CriteriaQuery<JobSearchResult> contentQuery=cb.createQuery(JobSearchResult.class);
    contentQuery.from(JobEntity.class);
    contentQuery.multiselect(root.get(JobEntity_.id),root.get(JobEntity_.name),root.get(JobEntity_.user),root.get(JobEntity_.status),root.get(JobEntity_.started),root.get(JobEntity_.finished),root.get(JobEntity_.clusterName),root.get(JobEntity_.commandName));
    contentQuery.where(whereClause);
    final Sort sort=page.getSort();
    final List<Order> orders=new ArrayList<>();
    sort.iterator().forEachRemaining(order -> {
      if (order.isAscending()) {
        orders.add(cb.asc(root.get(order.getProperty())));
      }
 else {
        orders.add(cb.desc(root.get(order.getProperty())));
      }
    }
);
    contentQuery.orderBy(orders);
    final List<JobSearchResult> results=this.entityManager.createQuery(contentQuery).setFirstResult(page.getOffset()).setMaxResults(page.getPageSize()).getResultList();
    return new PageImpl<>(results,page,count);
  }
 else {
    return new PageImpl<>(Lists.newArrayList());
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public Page<JobSearchResult> findJobs(final String id,final String jobName,final String user,final Set<JobStatus> statuses,final Set<String> tags,final String clusterName,final String clusterId,final String commandName,final String commandId,final Date minStarted,final Date maxStarted,final Date minFinished,final Date maxFinished,@NotNull final Pageable page){
  log.debug("String_Node_Str");
  final CriteriaBuilder cb=this.entityManager.getCriteriaBuilder();
  final CriteriaQuery<Long> countQuery=cb.createQuery(Long.class);
  final Root<JobEntity> root=countQuery.from(JobEntity.class);
  final Predicate whereClause=JpaJobSpecs.getFindPredicate(root,cb,id,jobName,user,statuses,tags,clusterName,clusterId == null ? null : this.clusterRepository.findOne(clusterId),commandName,commandId == null ? null : this.commandRepository.findOne(commandId),minStarted,maxStarted,minFinished,maxFinished);
  countQuery.select(cb.count(root)).where(whereClause);
  final Long count=this.entityManager.createQuery(countQuery).getSingleResult();
  if (count > 0) {
    final CriteriaQuery<JobSearchResult> contentQuery=cb.createQuery(JobSearchResult.class);
    contentQuery.from(JobEntity.class);
    contentQuery.multiselect(root.get(JobEntity_.id),root.get(JobEntity_.name),root.get(JobEntity_.user),root.get(JobEntity_.status),root.get(JobEntity_.started),root.get(JobEntity_.finished),root.get(JobEntity_.clusterName),root.get(JobEntity_.commandName));
    contentQuery.where(whereClause);
    final Sort sort=page.getSort();
    final List<Order> orders=new ArrayList<>();
    sort.iterator().forEachRemaining(order -> {
      if (order.isAscending()) {
        orders.add(cb.asc(root.get(order.getProperty())));
      }
 else {
        orders.add(cb.desc(root.get(order.getProperty())));
      }
    }
);
    contentQuery.orderBy(orders);
    final List<JobSearchResult> results=this.entityManager.createQuery(contentQuery).setFirstResult(page.getOffset()).setMaxResults(page.getPageSize()).getResultList();
    return new PageImpl<>(results,page,count);
  }
 else {
    return new PageImpl<>(Lists.newArrayList());
  }
}