Program: 175970
Project: 175970
Buggy source:
/** 
 * Method parse provided JPQL query into: 1. CQL3 query, in case cql3 is enabled or is a native query. 2. list of index clause, if cql2 is enabled. Then executes query for given min & max values for scrolling over results.
 * @param m entity metadata
 * @param client client
 * @return list of database values wrapped into entities.
 * @throws Exception throws exception, in case of run time error.
 */
private List<E> populateEntities(EntityMetadata m,Client client) throws Exception {
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str",((QueryImpl)query).getJPAQuery());
  }
  List<E> result=new ArrayList<E>();
  ApplicationMetadata appMetadata=kunderaMetadata.getApplicationMetadata();
  externalProperties=((CassandraClientBase)client).getExternalProperties();
  MetamodelImpl metaModel=(MetamodelImpl)kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  String queryString=appMetadata.getQuery(((QueryImpl)query).getJPAQuery());
  boolean isNative=((CassQuery)query).isNative();
  if (((CassandraClientBase)client).isCql3Enabled(m)) {
    String parsedQuery=query.onQueryOverCQL3(m,client,metaModel,null);
    parsedQuery=appendWhereClauseWithScroll(parsedQuery);
    results=parsedQuery != null ? ((CassandraClientBase)client).executeQuery(m.getEntityClazz(),m.getRelationNames(),isNative,parsedQuery) : null;
  }
 else {
    boolean useInvertedIndex=CassandraIndexHelper.isInvertedIndexingApplicable(m,MetadataUtils.useSecondryIndex(((ClientBase)client).getClientMetadata()));
    Map<Boolean,List<IndexClause>> ixClause=query.prepareIndexClause(m,useInvertedIndex);
    if (useInvertedIndex && !((QueryImpl)query).getKunderaQuery().getFilterClauseQueue().isEmpty()) {
      result=(List)((CassandraEntityReader)this.reader).readFromIndexTable(m,client,ixClause);
    }
 else {
      boolean isRowKeyQuery=ixClause.keySet().iterator().next();
      List<IndexExpression> expressions=!ixClause.get(isRowKeyQuery).isEmpty() ? ixClause.get(isRowKeyQuery).get(0).getExpressions() : null;
      Map<String,byte[]> rowKeys=((CassandraEntityReader)this.reader).getRowKeyValue(expressions,((AbstractAttribute)m.getIdAttribute()).getJPAColumnName());
      byte[] minValue=start == null ? rowKeys.get(MIN_) : start;
      byte[] maxVal=rowKeys.get(MAX_);
      results=((CassandraClientBase)client).findByRange(minValue,maxVal,m,m.getRelationNames() != null && !m.getRelationNames().isEmpty(),m.getRelationNames(),query.getColumnList(m,metaModel,((QueryImpl)query).getKunderaQuery().getResult(),null),expressions,maxResult);
      if (maxResult == 1) {
        maxResult++;
      }
 else       if (maxResult > 1 && checkOnEmptyResult() && maxResult != results.size()) {
        results=null;
      }
    }
  }
  return results;
}

Fixed version (ground truth):
/** 
 * Method parse provided JPQL query into: 1. CQL3 query, in case cql3 is enabled or is a native query. 2. list of index clause, if cql2 is enabled. Then executes query for given min & max values for scrolling over results.
 * @param m entity metadata
 * @param client client
 * @return list of database values wrapped into entities.
 * @throws Exception throws exception, in case of run time error.
 */
protected List<E> populateEntities(EntityMetadata m,Client client) throws Exception {
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str",((QueryImpl)query).getJPAQuery());
  }
  List<E> result=new ArrayList<E>();
  ApplicationMetadata appMetadata=kunderaMetadata.getApplicationMetadata();
  externalProperties=((CassandraClientBase)client).getExternalProperties();
  MetamodelImpl metaModel=(MetamodelImpl)kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  String queryString=appMetadata.getQuery(((QueryImpl)query).getJPAQuery());
  boolean isNative=((CassQuery)query).isNative();
  if (((CassandraClientBase)client).isCql3Enabled(m)) {
    String parsedQuery=query.onQueryOverCQL3(m,client,metaModel,null);
    parsedQuery=appendWhereClauseWithScroll(parsedQuery);
    results=parsedQuery != null ? ((CassandraClientBase)client).executeQuery(m.getEntityClazz(),m.getRelationNames(),isNative,parsedQuery) : null;
  }
 else {
    boolean useInvertedIndex=CassandraIndexHelper.isInvertedIndexingApplicable(m,MetadataUtils.useSecondryIndex(((ClientBase)client).getClientMetadata()));
    Map<Boolean,List<IndexClause>> ixClause=query.prepareIndexClause(m,useInvertedIndex);
    if (useInvertedIndex && !((QueryImpl)query).getKunderaQuery().getFilterClauseQueue().isEmpty()) {
      result=(List)((CassandraEntityReader)this.reader).readFromIndexTable(m,client,ixClause);
    }
 else {
      boolean isRowKeyQuery=ixClause.keySet().iterator().next();
      List<IndexExpression> expressions=!ixClause.get(isRowKeyQuery).isEmpty() ? ixClause.get(isRowKeyQuery).get(0).getExpressions() : null;
      Map<String,byte[]> rowKeys=((CassandraEntityReader)this.reader).getRowKeyValue(expressions,((AbstractAttribute)m.getIdAttribute()).getJPAColumnName());
      byte[] minValue=start == null ? rowKeys.get(MIN_) : start;
      byte[] maxVal=rowKeys.get(MAX_);
      results=((CassandraClientBase)client).findByRange(minValue,maxVal,m,m.getRelationNames() != null && !m.getRelationNames().isEmpty(),m.getRelationNames(),query.getColumnList(m,metaModel,((QueryImpl)query).getKunderaQuery().getResult(),null),expressions,maxResult);
      if (maxResult == 1) {
        maxResult++;
      }
 else       if (maxResult > 1 && checkOnEmptyResult() && maxResult != results.size()) {
        results=null;
      }
    }
  }
  return results;
}