Program: 168810
Project: 168810
Buggy source:
@Override public List<Object[]> transform(List<Object[]> tuples){
  FixedArrayList correlationParams=new FixedArrayList(batchSize);
  int tupleOffset=batchSize > 1 ? 1 : 0;
  Iterator<Object[]> tupleListIter=tuples.iterator();
  final String correlationRoot=applyAndGetCorrelationRoot(expectBatchCorrelationValues);
  EntityManager em=criteriaBuilder.getEntityManager();
  if (viewRootJpqlMacro.usesViewRoot()) {
    int totalSize=tuples.size();
    Map<Object,Map<Object,TuplePromise>> viewRoots=new HashMap<Object,Map<Object,TuplePromise>>(totalSize);
    Map<Object,Map<Object,TuplePromise>> correlationValues=new HashMap<Object,Map<Object,TuplePromise>>(totalSize);
    while (tupleListIter.hasNext()) {
      Object[] tuple=tupleListIter.next();
      Object viewRootKey=tuple[0];
      Object correlationValueKey=tuple[startIndex];
      Map<Object,TuplePromise> viewRootCorrelationValues=viewRoots.get(viewRootKey);
      if (viewRootCorrelationValues == null) {
        viewRootCorrelationValues=new HashMap<Object,TuplePromise>();
        viewRoots.put(viewRootKey,viewRootCorrelationValues);
      }
      TuplePromise viewRootPromise=viewRootCorrelationValues.get(correlationValueKey);
      if (viewRootPromise == null) {
        viewRootPromise=new TuplePromise(startIndex);
        viewRootCorrelationValues.put(correlationValueKey,viewRootPromise);
      }
      viewRootPromise.add(tuple);
      Map<Object,TuplePromise> correlationValueViewRoots=correlationValues.get(correlationValueKey);
      if (correlationValueViewRoots == null) {
        correlationValueViewRoots=new HashMap<Object,TuplePromise>();
        correlationValues.put(correlationValueKey,correlationValueViewRoots);
      }
      TuplePromise correlationValuePromise=correlationValueViewRoots.get(viewRootKey);
      if (correlationValuePromise == null) {
        correlationValuePromise=new TuplePromise(startIndex);
        correlationValueViewRoots.put(viewRootKey,correlationValuePromise);
      }
      correlationValuePromise.add(tuple);
    }
    boolean batchCorrelationValues=viewRoots.size() <= correlationValues.size();
    FixedArrayList viewRootIds=new FixedArrayList(batchSize);
    if (batchCorrelationValues) {
      if (batchSize > 1) {
        if (!expectBatchCorrelationValues) {
          applyAndGetCorrelationRoot(true);
        }
        criteriaBuilder.select(correlationKeyExpression);
      }
      correlator.finish(criteriaBuilder,entityViewConfiguration,tupleOffset,correlationRoot);
      populateParameters(criteriaBuilder);
      query=criteriaBuilder.getQuery();
      for (      Map.Entry<Object,Map<Object,TuplePromise>> batchEntry : viewRoots.entrySet()) {
        Map<Object,TuplePromise> batchValues=batchEntry.getValue();
        for (        Map.Entry<Object,TuplePromise> batchValueEntry : batchValues.entrySet()) {
          if (correlationBasisEntity != null) {
            correlationParams.add(em.getReference(correlationBasisEntity,batchValueEntry.getKey()));
          }
 else {
            correlationParams.add(batchValueEntry.getKey());
          }
          if (batchSize == correlationParams.realSize()) {
            viewRootIds.add(batchEntry.getKey());
            batchLoad(batchValues,correlationParams,viewRootIds,correlationParams.get(0),true);
          }
        }
        if (correlationParams.realSize() > 0) {
          viewRootIds.add(batchEntry.getKey());
          batchLoad(batchValues,correlationParams,viewRootIds,null,true);
        }
      }
      fillDefaultValues(viewRoots);
    }
 else {
      if (batchSize > 1) {
        if (expectBatchCorrelationValues) {
          applyAndGetCorrelationRoot(false);
        }
        criteriaBuilder.select(correlationKeyExpression);
      }
      correlator.finish(criteriaBuilder,entityViewConfiguration,tupleOffset,correlationRoot);
      populateParameters(criteriaBuilder);
      query=criteriaBuilder.getQuery();
      for (      Map.Entry<Object,Map<Object,TuplePromise>> batchEntry : correlationValues.entrySet()) {
        Map<Object,TuplePromise> batchValues=batchEntry.getValue();
        for (        Map.Entry<Object,TuplePromise> batchValueEntry : batchValues.entrySet()) {
          if (viewRootJpqlMacro.usesViewRootEntityParameter()) {
            viewRootIds.add(em.getReference(viewRootType.getEntityClass(),batchValueEntry.getKey()));
          }
 else {
            viewRootIds.add(batchValueEntry.getKey());
          }
          if (batchSize == viewRootIds.realSize()) {
            if (correlationBasisEntity != null) {
              correlationParams.add(em.getReference(correlationBasisEntity,batchEntry.getKey()));
            }
 else {
              correlationParams.add(batchEntry.getKey());
            }
            batchLoad(batchValues,correlationParams,viewRootIds,viewRootIds.get(0),false);
          }
        }
        if (viewRootIds.realSize() > 0) {
          if (correlationBasisEntity != null) {
            correlationParams.add(em.getReference(correlationBasisEntity,batchEntry.getKey()));
          }
 else {
            correlationParams.add(batchEntry.getKey());
          }
          batchLoad(batchValues,correlationParams,viewRootIds,null,false);
        }
      }
      fillDefaultValues(correlationValues);
    }
  }
 else {
    if (batchSize > 1) {
      if (!expectBatchCorrelationValues) {
        applyAndGetCorrelationRoot(true);
      }
      criteriaBuilder.select(correlationKeyExpression);
    }
    correlator.finish(criteriaBuilder,entityViewConfiguration,tupleOffset,correlationRoot);
    populateParameters(criteriaBuilder);
    query=criteriaBuilder.getQuery();
    Map<Object,TuplePromise> correlationValues=new HashMap<Object,TuplePromise>(tuples.size());
    while (tupleListIter.hasNext()) {
      Object[] tuple=tupleListIter.next();
      Object correlationValue=tuple[startIndex];
      TuplePromise tupleIndexValue=correlationValues.get(correlationValue);
      if (tupleIndexValue == null) {
        tupleIndexValue=new TuplePromise(startIndex);
        tupleIndexValue.add(tuple);
        correlationValues.put(correlationValue,tupleIndexValue);
        if (correlationBasisEntity != null) {
          correlationParams.add(em.getReference(correlationBasisEntity,tuple[startIndex]));
        }
 else {
          correlationParams.add(tuple[startIndex]);
        }
        if (batchSize == correlationParams.realSize()) {
          batchLoad(correlationValues,correlationParams,null,correlationParams.get(0),batchSize > 1);
        }
      }
 else {
        tupleIndexValue.add(tuple);
      }
    }
    if (correlationParams.realSize() > 0) {
      batchLoad(correlationValues,correlationParams,null,null,correlationParams.realSize() > 1);
    }
    fillDefaultValues(Collections.singletonMap(null,correlationValues));
  }
  return tuples;
}

Fixed version (ground truth):
@Override public List<Object[]> transform(List<Object[]> tuples){
  FixedArrayList correlationParams=new FixedArrayList(batchSize);
  int tupleOffset=batchSize > 1 ? 1 : 0;
  Iterator<Object[]> tupleListIter=tuples.iterator();
  final String correlationRoot=applyAndGetCorrelationRoot(expectBatchCorrelationValues);
  EntityManager em=criteriaBuilder.getEntityManager();
  if (viewRootJpqlMacro.usesViewRoot()) {
    int totalSize=tuples.size();
    Map<Object,Map<Object,TuplePromise>> viewRoots=new HashMap<Object,Map<Object,TuplePromise>>(totalSize);
    Map<Object,Map<Object,TuplePromise>> correlationValues=new HashMap<Object,Map<Object,TuplePromise>>(totalSize);
    while (tupleListIter.hasNext()) {
      Object[] tuple=tupleListIter.next();
      Object viewRootKey=tuple[0];
      Object correlationValueKey=tuple[startIndex];
      Map<Object,TuplePromise> viewRootCorrelationValues=viewRoots.get(viewRootKey);
      if (viewRootCorrelationValues == null) {
        viewRootCorrelationValues=new HashMap<Object,TuplePromise>();
        viewRoots.put(viewRootKey,viewRootCorrelationValues);
      }
      TuplePromise viewRootPromise=viewRootCorrelationValues.get(correlationValueKey);
      if (viewRootPromise == null) {
        viewRootPromise=new TuplePromise(startIndex);
        viewRootCorrelationValues.put(correlationValueKey,viewRootPromise);
      }
      viewRootPromise.add(tuple);
      Map<Object,TuplePromise> correlationValueViewRoots=correlationValues.get(correlationValueKey);
      if (correlationValueViewRoots == null) {
        correlationValueViewRoots=new HashMap<Object,TuplePromise>();
        correlationValues.put(correlationValueKey,correlationValueViewRoots);
      }
      TuplePromise correlationValuePromise=correlationValueViewRoots.get(viewRootKey);
      if (correlationValuePromise == null) {
        correlationValuePromise=new TuplePromise(startIndex);
        correlationValueViewRoots.put(viewRootKey,correlationValuePromise);
      }
      correlationValuePromise.add(tuple);
    }
    boolean batchCorrelationValues=viewRoots.size() <= correlationValues.size();
    FixedArrayList viewRootIds=new FixedArrayList(batchSize);
    if (batchCorrelationValues) {
      if (batchSize > 1) {
        if (!expectBatchCorrelationValues) {
          applyAndGetCorrelationRoot(true);
        }
        criteriaBuilder.select(correlationKeyExpression);
      }
      correlator.finish(criteriaBuilder,entityViewConfiguration,tupleOffset,correlationRoot);
      populateParameters(criteriaBuilder);
      query=criteriaBuilder.getQuery();
      for (      Map.Entry<Object,Map<Object,TuplePromise>> batchEntry : viewRoots.entrySet()) {
        Map<Object,TuplePromise> batchValues=batchEntry.getValue();
        for (        Map.Entry<Object,TuplePromise> batchValueEntry : batchValues.entrySet()) {
          if (correlationBasisEntity != null) {
            correlationParams.add(em.getReference(correlationBasisEntity,batchValueEntry.getKey()));
          }
 else {
            correlationParams.add(batchValueEntry.getKey());
          }
          if (batchSize == correlationParams.realSize()) {
            viewRootIds.add(batchEntry.getKey());
            batchLoad(batchValues,correlationParams,viewRootIds,correlationParams.get(0),true);
          }
        }
        if (correlationParams.realSize() > 0) {
          viewRootIds.add(batchEntry.getKey());
          batchLoad(batchValues,correlationParams,viewRootIds,null,true);
        }
      }
      fillDefaultValues(viewRoots);
    }
 else {
      if (batchSize > 1) {
        if (expectBatchCorrelationValues) {
          applyAndGetCorrelationRoot(false);
        }
        criteriaBuilder.select(correlationKeyExpression);
      }
      correlator.finish(criteriaBuilder,entityViewConfiguration,tupleOffset,correlationRoot);
      populateParameters(criteriaBuilder);
      query=criteriaBuilder.getQuery();
      for (      Map.Entry<Object,Map<Object,TuplePromise>> batchEntry : correlationValues.entrySet()) {
        Map<Object,TuplePromise> batchValues=batchEntry.getValue();
        for (        Map.Entry<Object,TuplePromise> batchValueEntry : batchValues.entrySet()) {
          if (viewRootJpqlMacro.usesViewRootEntityParameter()) {
            viewRootIds.add(em.getReference(viewRootType.getEntityClass(),batchValueEntry.getKey()));
          }
 else {
            viewRootIds.add(batchValueEntry.getKey());
          }
          if (batchSize == viewRootIds.realSize()) {
            if (correlationBasisEntity != null) {
              correlationParams.add(em.getReference(correlationBasisEntity,batchEntry.getKey()));
            }
 else {
              correlationParams.add(batchEntry.getKey());
            }
            batchLoad(batchValues,correlationParams,viewRootIds,viewRootIds.get(0),false);
          }
        }
        if (viewRootIds.realSize() > 0) {
          if (correlationBasisEntity != null) {
            correlationParams.add(em.getReference(correlationBasisEntity,batchEntry.getKey()));
          }
 else {
            correlationParams.add(batchEntry.getKey());
          }
          batchLoad(batchValues,correlationParams,viewRootIds,null,false);
        }
      }
      fillDefaultValues(correlationValues);
    }
  }
 else {
    if (batchSize > 1) {
      if (!expectBatchCorrelationValues) {
        applyAndGetCorrelationRoot(true);
      }
      criteriaBuilder.select(correlationKeyExpression);
    }
    correlator.finish(criteriaBuilder,entityViewConfiguration,tupleOffset,correlationRoot);
    populateParameters(criteriaBuilder);
    query=criteriaBuilder.getQuery();
    Map<Object,TuplePromise> correlationValues=new HashMap<Object,TuplePromise>(tuples.size());
    while (tupleListIter.hasNext()) {
      Object[] tuple=tupleListIter.next();
      Object correlationValue=tuple[startIndex];
      TuplePromise tupleIndexValue=correlationValues.get(correlationValue);
      if (tupleIndexValue == null) {
        tupleIndexValue=new TuplePromise(startIndex);
        tupleIndexValue.add(tuple);
        correlationValues.put(correlationValue,tupleIndexValue);
        if (correlationBasisEntity != null) {
          correlationParams.add(em.getReference(correlationBasisEntity,tuple[startIndex]));
        }
 else {
          correlationParams.add(tuple[startIndex]);
        }
        if (batchSize == correlationParams.realSize()) {
          batchLoad(correlationValues,correlationParams,null,correlationParams.get(0),batchSize > 1);
        }
      }
 else {
        tupleIndexValue.add(tuple);
      }
    }
    if (correlationParams.realSize() > 0) {
      batchLoad(correlationValues,correlationParams,null,null,batchSize > 1);
    }
    fillDefaultValues(Collections.singletonMap(null,correlationValues));
  }
  return tuples;
}