Program: 64233
Project: 64233
Buggy source:
/** 
 * INTERNAL: Prepare and execute the batch query and store the results for each source object in a map keyed by the mappings source keys of the source objects.
 */
@Override protected void executeBatchQuery(DatabaseQuery query,CacheKey parentCacheKey,Map referenceObjectsByKey,AbstractSession session,AbstractRecord translationRow){
  ReadAllQuery batchQuery=(ReadAllQuery)query;
  ComplexQueryResult complexResult=(ComplexQueryResult)session.executeQuery(batchQuery,translationRow);
  Object results=complexResult.getResult();
  Iterator<AbstractRecord> rowsIterator=((List<AbstractRecord>)complexResult.getData()).iterator();
  ContainerPolicy queryContainerPolicy=batchQuery.getContainerPolicy();
  if (this.containerPolicy.shouldAddAll()) {
    Map<Object,List[]> referenceObjectsAndRowsByKey=new HashMap();
    for (Object objectsIterator=queryContainerPolicy.iteratorFor(results); queryContainerPolicy.hasNext(objectsIterator); ) {
      Object eachReferenceObject=queryContainerPolicy.next(objectsIterator,session);
      AbstractRecord row=rowsIterator.next();
      Object eachReferenceKey=extractKeyFromTargetRow(row,session);
      List[] objectsAndRows=referenceObjectsAndRowsByKey.get(eachReferenceKey);
      if (objectsAndRows == null) {
        objectsAndRows=new List[]{new ArrayList(),new ArrayList()};
        referenceObjectsAndRowsByKey.put(eachReferenceKey,objectsAndRows);
      }
      objectsAndRows[0].add(eachReferenceObject);
      objectsAndRows[1].add(row);
    }
    Iterator<Map.Entry<Object,List[]>> iterator=referenceObjectsAndRowsByKey.entrySet().iterator();
    while (iterator.hasNext()) {
      Map.Entry<Object,List[]> entry=iterator.next();
      Object eachReferenceKey=entry.getKey();
      List objects=entry.getValue()[0];
      List<AbstractRecord> rows=entry.getValue()[1];
      Object container=this.containerPolicy.containerInstance(objects.size());
      this.containerPolicy.addAll(objects,container,query.getSession(),rows,batchQuery,parentCacheKey,true);
      referenceObjectsByKey.put(eachReferenceKey,container);
    }
  }
 else {
    for (Object objectsIterator=queryContainerPolicy.iteratorFor(results); queryContainerPolicy.hasNext(objectsIterator); ) {
      Object eachReferenceObject=queryContainerPolicy.next(objectsIterator,session);
      AbstractRecord row=rowsIterator.next();
      Object eachReferenceKey=extractKeyFromTargetRow(row,session);
      Object container=referenceObjectsByKey.get(eachReferenceKey);
      if ((container == null) || (container == Helper.NULL_VALUE)) {
        container=this.containerPolicy.containerInstance();
        referenceObjectsByKey.put(eachReferenceKey,container);
      }
      this.containerPolicy.addInto(eachReferenceObject,container,session,row,batchQuery,parentCacheKey,true);
    }
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL: Prepare and execute the batch query and store the results for each source object in a map keyed by the mappings source keys of the source objects.
 */
@Override protected void executeBatchQuery(DatabaseQuery query,CacheKey parentCacheKey,Map referenceObjectsByKey,AbstractSession session,AbstractRecord translationRow){
  ReadAllQuery batchQuery=(ReadAllQuery)query;
  ComplexQueryResult complexResult=(ComplexQueryResult)session.executeQuery(batchQuery,translationRow);
  Object results=complexResult.getResult();
  Iterator<AbstractRecord> rowsIterator=((List<AbstractRecord>)complexResult.getData()).iterator();
  ContainerPolicy queryContainerPolicy=batchQuery.getContainerPolicy();
  if (this.containerPolicy.shouldAddAll()) {
    Map<Object,List[]> referenceObjectsAndRowsByKey=new HashMap();
    for (Object objectsIterator=queryContainerPolicy.iteratorFor(results); queryContainerPolicy.hasNext(objectsIterator); ) {
      Object eachReferenceObject=queryContainerPolicy.next(objectsIterator,session);
      AbstractRecord row=rowsIterator.next();
      Object eachReferenceKey=extractKeyFromTargetRow(row,session);
      List[] objectsAndRows=referenceObjectsAndRowsByKey.get(eachReferenceKey);
      if (objectsAndRows == null) {
        objectsAndRows=new List[]{new ArrayList(),new ArrayList()};
        referenceObjectsAndRowsByKey.put(eachReferenceKey,objectsAndRows);
      }
      objectsAndRows[0].add(eachReferenceObject);
      objectsAndRows[1].add(row);
    }
    Iterator<Map.Entry<Object,List[]>> iterator=referenceObjectsAndRowsByKey.entrySet().iterator();
    while (iterator.hasNext()) {
      Map.Entry<Object,List[]> entry=iterator.next();
      Object eachReferenceKey=entry.getKey();
      List objects=entry.getValue()[0];
      List<AbstractRecord> rows=entry.getValue()[1];
      Object container=this.containerPolicy.containerInstance(objects.size());
      this.containerPolicy.addAll(objects,container,query.getSession(),rows,batchQuery,parentCacheKey,true);
      referenceObjectsByKey.put(eachReferenceKey,container);
    }
  }
 else {
    for (Object objectsIterator=queryContainerPolicy.iteratorFor(results); queryContainerPolicy.hasNext(objectsIterator); ) {
      Object eachReferenceObject=queryContainerPolicy.next(objectsIterator,session);
      AbstractRecord row=rowsIterator.next();
      while (row == null && rowsIterator.hasNext()) {
        row=rowsIterator.next();
      }
      Object eachReferenceKey=extractKeyFromTargetRow(row,session);
      Object container=referenceObjectsByKey.get(eachReferenceKey);
      if ((container == null) || (container == Helper.NULL_VALUE)) {
        container=this.containerPolicy.containerInstance();
        referenceObjectsByKey.put(eachReferenceKey,container);
      }
      this.containerPolicy.addInto(eachReferenceObject,container,session,row,batchQuery,parentCacheKey,true);
    }
  }
}