Program: 59391
Project: 59391
Buggy source:
/** 
 * Execute a select query on entityClass using <a href="http://www.querydsl.com/">Querydsl</a> which enables the construction of type-safe SQL-like queries.
 * @param entity builder for entity to use in search. Represents the entityand gives access to its properties for query purposes
 * @param filterByAssociations (optional) for each related entity to joincontain as key the name of the association and as value the List of related entity fields to filter by
 * @param orderByAssociations (optional) for each related entity to ordercontain as key the name of the association and as value the List of related entity fields to order by
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @param distinct use distinct query
 * @return
 */
public static <T,E extends Comparable<?>>SearchResults<T> findByCriteria(PathBuilder<T> entity,Map<String,List<String>> filterByAssociations,Map<String,List<String>> orderByAssociations,EntityManager entityManager,DatatablesCriterias datatablesCriterias,BooleanBuilder basePredicate,boolean distinct) throws IllegalArgumentException {
  Assert.notNull(entityManager);
  Assert.notNull(datatablesCriterias);
  if (CollectionUtils.isEmpty(filterByAssociations)) {
    filterByAssociations=new HashMap<String,List<String>>();
  }
  if (CollectionUtils.isEmpty(orderByAssociations)) {
    orderByAssociations=new HashMap<String,List<String>>();
  }
  boolean isPaged=datatablesCriterias.getDisplaySize() != null && datatablesCriterias.getDisplaySize() > 0;
  boolean findInAllColumns=StringUtils.isNotEmpty(datatablesCriterias.getSearch()) && datatablesCriterias.hasOneFilterableColumn();
  JPAQuery query=new JPAQuery(entityManager);
  query=query.from(entity);
  JPAQuery baseQuery=new JPAQuery(entityManager);
  baseQuery=baseQuery.from(entity);
  Map<String,PathBuilder<?>> associationMap=new HashMap<String,PathBuilder<?>>();
  query=prepareQueryAssociationMap(entity,filterByAssociations,datatablesCriterias,findInAllColumns,query,associationMap);
  BooleanBuilder filtersByColumnPredicate=new BooleanBuilder();
  BooleanBuilder filtersByTablePredicate=new BooleanBuilder();
  try {
    if (datatablesCriterias.hasOneFilteredColumn()) {
      filtersByColumnPredicate=prepareQueryFilterPart(entity,filterByAssociations,datatablesCriterias,associationMap,filtersByColumnPredicate);
    }
    filtersByTablePredicate=prepareQuerySearchPart(entity,filterByAssociations,datatablesCriterias,findInAllColumns,associationMap,filtersByTablePredicate);
  }
 catch (  Exception e) {
    SearchResults<T> searchResults=new SearchResults<T>(new ArrayList<T>(0),0,isPaged,new Long(datatablesCriterias.getDisplayStart()),new Long(datatablesCriterias.getDisplaySize()),0);
    return searchResults;
  }
  List<OrderSpecifier<?>> orderSpecifiersList=prepareQueryOrder(entity,orderByAssociations,datatablesCriterias,associationMap);
  Long offset=null;
  Long limit=null;
  if (isPaged) {
    limit=new Long(datatablesCriterias.getDisplaySize());
  }
  if (datatablesCriterias.getDisplayStart() != null && datatablesCriterias.getDisplayStart() >= 0) {
    offset=new Long(datatablesCriterias.getDisplayStart());
  }
  QueryModifiers queryModifiers=new QueryModifiers(limit,offset);
  List<T> elements=null;
  if (distinct) {
    query=query.distinct();
  }
  if (basePredicate == null) {
    basePredicate=new BooleanBuilder();
  }
  baseQuery.where(basePredicate);
  query=query.where(basePredicate.and(filtersByColumnPredicate.getValue()).and(filtersByTablePredicate.getValue()));
  query.restrict(queryModifiers);
  long totalResultCount=0;
  if (isPaged) {
    totalResultCount=query.count();
  }
  elements=query.orderBy(orderSpecifiersList.toArray(new OrderSpecifier[orderSpecifiersList.size()])).list(entity);
  if (!isPaged) {
    totalResultCount=elements.size();
  }
  long totalBaseCount=baseQuery.count();
  if (offset == null) {
    offset=new Long(0);
  }
  if (limit == null) {
    limit=totalBaseCount;
  }
  SearchResults<T> searchResults=new SearchResults<T>(elements,totalResultCount,isPaged,offset,limit,totalBaseCount);
  return searchResults;
}

Fixed version (ground truth):
/** 
 * Execute a select query on entityClass using <a href="http://www.querydsl.com/">Querydsl</a> which enables the construction of type-safe SQL-like queries.
 * @param entity builder for entity to use in search. Represents the entityand gives access to its properties for query purposes
 * @param filterByAssociations (optional) for each related entity to joincontain as key the name of the association and as value the List of related entity fields to filter by
 * @param orderByAssociations (optional) for each related entity to ordercontain as key the name of the association and as value the List of related entity fields to order by
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @param distinct use distinct query
 * @return
 */
public static <T,E extends Comparable<?>>SearchResults<T> findByCriteria(PathBuilder<T> entity,Map<String,List<String>> filterByAssociations,Map<String,List<String>> orderByAssociations,EntityManager entityManager,DatatablesCriterias datatablesCriterias,BooleanBuilder basePredicate,boolean distinct) throws IllegalArgumentException {
  Assert.notNull(entityManager);
  Assert.notNull(datatablesCriterias);
  if (CollectionUtils.isEmpty(filterByAssociations)) {
    filterByAssociations=new HashMap<String,List<String>>();
  }
  if (CollectionUtils.isEmpty(orderByAssociations)) {
    orderByAssociations=new HashMap<String,List<String>>();
  }
  boolean isPaged=datatablesCriterias.getDisplaySize() != null && datatablesCriterias.getDisplaySize() > 0;
  boolean findInAllColumns=StringUtils.isNotEmpty(datatablesCriterias.getSearch()) && datatablesCriterias.hasOneFilterableColumn();
  JPAQuery query=new JPAQuery(entityManager);
  query=query.from(entity);
  JPAQuery baseQuery=new JPAQuery(entityManager);
  baseQuery=baseQuery.from(entity);
  Map<String,PathBuilder<?>> associationMap=new HashMap<String,PathBuilder<?>>();
  query=prepareQueryAssociationMap(entity,filterByAssociations,datatablesCriterias,findInAllColumns,query,associationMap);
  BooleanBuilder filtersByColumnPredicate=new BooleanBuilder();
  BooleanBuilder filtersByTablePredicate=new BooleanBuilder();
  try {
    if (datatablesCriterias.hasOneFilteredColumn()) {
      filtersByColumnPredicate=prepareQueryFilterPart(entity,filterByAssociations,datatablesCriterias,associationMap,filtersByColumnPredicate);
    }
    filtersByTablePredicate=prepareQuerySearchPart(entity,filterByAssociations,datatablesCriterias,findInAllColumns,associationMap,filtersByTablePredicate);
  }
 catch (  Exception e) {
    SearchResults<T> searchResults=new SearchResults<T>(new ArrayList<T>(0),0,isPaged,new Long(datatablesCriterias.getDisplayStart()),new Long(datatablesCriterias.getDisplaySize()),0);
    return searchResults;
  }
  List<OrderSpecifier<?>> orderSpecifiersList=prepareQueryOrder(entity,orderByAssociations,datatablesCriterias,associationMap);
  Long offset=null;
  Long limit=null;
  if (isPaged) {
    limit=new Long(datatablesCriterias.getDisplaySize());
  }
  if (datatablesCriterias.getDisplayStart() != null && datatablesCriterias.getDisplayStart() >= 0) {
    offset=new Long(datatablesCriterias.getDisplayStart());
  }
  QueryModifiers queryModifiers=new QueryModifiers(limit,offset);
  List<T> elements=null;
  if (distinct) {
    query=query.distinct();
  }
  if (basePredicate == null) {
    basePredicate=new BooleanBuilder();
  }
  baseQuery.where(basePredicate);
  query=query.where(basePredicate.and(filtersByColumnPredicate.getValue()).and(filtersByTablePredicate.getValue()));
  long totalResultCount=0;
  if (isPaged) {
    totalResultCount=query.count();
  }
  elements=query.orderBy(orderSpecifiersList.toArray(new OrderSpecifier[orderSpecifiersList.size()])).restrict(queryModifiers).list(entity);
  if (!isPaged) {
    totalResultCount=elements.size();
  }
  long totalBaseCount=baseQuery.count();
  if (offset == null) {
    offset=new Long(0);
  }
  if (limit == null) {
    limit=totalBaseCount;
  }
  SearchResults<T> searchResults=new SearchResults<T>(elements,totalResultCount,isPaged,offset,limit,totalBaseCount);
  return searchResults;
}