Program: 176270
Project: 176270
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.INSTANCE.getApplicationMetadata();
  externalProperties=((CassandraClientBase)client).getExternalProperties();
  MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  if (!appMetadata.isNative(((QueryImpl)query).getJPAQuery()) && ((CassandraClientBase)client).isCql3Enabled(m)) {
    String parsedQuery=query.onQueryOverCQL3(m,client,metaModel,null);
    parsedQuery=appendWhereClauseWithScroll(parsedQuery);
    results=parsedQuery != null ? ((CassandraClientBase)client).executeQuery(parsedQuery,m.getEntityClazz(),m.getRelationNames()) : null;
  }
 else {
    if (appMetadata.isNative(((QueryImpl)query).getJPAQuery())) {
      final String nativeQuery=appendWhereClauseWithScroll(((QueryImpl)query).getJPAQuery());
      results=nativeQuery != null ? ((CassandraClientBase)client).executeQuery(nativeQuery,m.getEntityClazz(),null) : 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,((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.
 */
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.INSTANCE.getApplicationMetadata();
  externalProperties=((CassandraClientBase)client).getExternalProperties();
  MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
  String queryString=appMetadata.getQuery(((QueryImpl)query).getJPAQuery());
  boolean isNative=((CassQuery)query).isNative();
  if (!isNative && ((CassandraClientBase)client).isCql3Enabled(m)) {
    String parsedQuery=query.onQueryOverCQL3(m,client,metaModel,null);
    parsedQuery=appendWhereClauseWithScroll(parsedQuery);
    results=parsedQuery != null ? ((CassandraClientBase)client).executeQuery(parsedQuery,m.getEntityClazz(),m.getRelationNames()) : null;
  }
 else {
    if (isNative) {
      final String nativeQuery=appendWhereClauseWithScroll(queryString != null ? queryString : ((QueryImpl)query).getJPAQuery());
      results=nativeQuery != null ? ((CassandraClientBase)client).executeQuery(nativeQuery,m.getEntityClazz(),null) : 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,((QueryImpl)query).getKunderaQuery().getResult(),null),expressions,maxResult);
        if (maxResult == 1) {
          maxResult++;
        }
 else         if (maxResult > 1 && checkOnEmptyResult() && maxResult != results.size()) {
          results=null;
        }
      }
    }
  }
  return results;
}