Program: 64234
Project: 64234
Buggy source:
/** 
 * INTERNAL: Extract the value from the batch optimized query, this should be supported by most query types.
 */
public Object extractResultFromBatchQuery(ReadQuery batchQuery,CacheKey parentCacheKey,AbstractRecord sourceRow,AbstractSession session,ObjectLevelReadQuery originalQuery) throws QueryException {
  Map<Object,Object> batchedObjects=null;
  Object result=null;
  Object sourceKey=extractBatchKeyFromRow(sourceRow,session);
  if (sourceKey == null) {
    return null;
  }
  Object cachedObject=checkCacheForBatchKey(sourceRow,sourceKey,batchedObjects,batchQuery,originalQuery,session);
  if (cachedObject != null) {
    return cachedObject;
  }
synchronized (batchQuery) {
    batchedObjects=batchQuery.getBatchObjects();
    BatchFetchPolicy originalPolicy=originalQuery.getBatchFetchPolicy();
    if (batchedObjects == null) {
      batchedObjects=new Hashtable();
      batchQuery.setBatchObjects(batchedObjects);
    }
 else {
      result=batchedObjects.get(sourceKey);
      if (result == Helper.NULL_VALUE) {
        return null;
      }
 else       if ((result != null) || (!originalPolicy.isIN())) {
        return result;
      }
    }
    if (result == null) {
      AbstractRecord translationRow=originalQuery.getTranslationRow();
      if (originalPolicy.isIN()) {
        List<AbstractRecord> parentRows=originalPolicy.getDataResults(this);
        int rowsSize=parentRows.size();
        int size=Math.min(rowsSize,originalPolicy.getSize());
        if (size == 0) {
          return null;
        }
        int startIndex=0;
        if (size != rowsSize) {
          startIndex=parentRows.indexOf(sourceRow);
        }
        List foreignKeyValues=new ArrayList(size);
        Set foreignKeys=new HashSet(size);
        int index=0;
        int offset=startIndex;
        for (int count=0; count < size; count++) {
          if (index >= rowsSize) {
            break;
          }
 else           if ((offset + index) >= rowsSize) {
            offset=index * -1;
          }
          AbstractRecord row=parentRows.get(offset + index);
          Object foreignKey=extractBatchKeyFromRow(row,session);
          if (foreignKey == null) {
            count--;
          }
 else {
            cachedObject=checkCacheForBatchKey(row,foreignKey,batchedObjects,batchQuery,originalQuery,session);
            if (cachedObject != null) {
              count--;
            }
 else {
              if (foreignKeys.contains(foreignKey)) {
                count--;
              }
 else {
                Object[] key=((CacheId)foreignKey).getPrimaryKey();
                Object foreignKeyValue=key[0];
                if (key.length > 1) {
                  foreignKeyValue=Arrays.asList(key);
                }
                foreignKeyValues.add(foreignKeyValue);
                foreignKeys.add(foreignKey);
              }
            }
          }
          index++;
        }
        List<AbstractRecord> remainingParentRows=null;
        if (startIndex == 0) {
          remainingParentRows=new ArrayList(parentRows.subList(index,rowsSize));
        }
 else         if (startIndex == offset) {
          remainingParentRows=new ArrayList(parentRows.subList(0,startIndex - 1));
          remainingParentRows.addAll(parentRows.subList(index,rowsSize));
        }
 else {
          if ((offset + index) >= (startIndex - 1)) {
            remainingParentRows=new ArrayList(0);
          }
 else {
            remainingParentRows=new ArrayList(parentRows.subList(offset + index,startIndex - 1));
          }
        }
        originalPolicy.setDataResults(this,remainingParentRows);
        translationRow=translationRow.clone();
        translationRow.put(QUERY_BATCH_PARAMETER,foreignKeyValues);
        for (        Object foreignKey : foreignKeys) {
          batchedObjects.put(foreignKey,Helper.NULL_VALUE);
        }
      }
 else       if (batchQuery.isReadAllQuery() && ((ReadAllQuery)batchQuery).getBatchFetchPolicy().isIN()) {
        throw QueryException.originalQueryMustUseBatchIN(this,originalQuery);
      }
      executeBatchQuery(batchQuery,parentCacheKey,batchedObjects,session,translationRow);
      batchQuery.setSession(null);
    }
  }
  result=batchedObjects.get(sourceKey);
  if (result == Helper.NULL_VALUE) {
    return null;
  }
 else {
    return result;
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL: Extract the value from the batch optimized query, this should be supported by most query types.
 */
public Object extractResultFromBatchQuery(ReadQuery batchQuery,CacheKey parentCacheKey,AbstractRecord sourceRow,AbstractSession session,ObjectLevelReadQuery originalQuery) throws QueryException {
  Map<Object,Object> batchedObjects=null;
  Object result=null;
  Object sourceKey=extractBatchKeyFromRow(sourceRow,session);
  if (sourceKey == null) {
    return null;
  }
  Object cachedObject=checkCacheForBatchKey(sourceRow,sourceKey,batchedObjects,batchQuery,originalQuery,session);
  if (cachedObject != null) {
    return cachedObject;
  }
synchronized (batchQuery) {
    batchedObjects=batchQuery.getBatchObjects();
    BatchFetchPolicy originalPolicy=originalQuery.getBatchFetchPolicy();
    if (batchedObjects == null) {
      batchedObjects=new Hashtable();
      batchQuery.setBatchObjects(batchedObjects);
    }
 else {
      result=batchedObjects.get(sourceKey);
      if (result == Helper.NULL_VALUE) {
        return null;
      }
 else       if ((result != null) || (!originalPolicy.isIN())) {
        return result;
      }
    }
    if (result == null) {
      AbstractRecord translationRow=originalQuery.getTranslationRow();
      if (originalPolicy.isIN()) {
        List<AbstractRecord> parentRows=originalPolicy.getDataResults(this);
        int rowsSize=parentRows.size();
        int size=Math.min(rowsSize,originalPolicy.getSize());
        if (size == 0) {
          return null;
        }
        int startIndex=0;
        if (size != rowsSize) {
          startIndex=parentRows.indexOf(sourceRow);
        }
        List foreignKeyValues=new ArrayList(size);
        Set foreignKeys=new HashSet(size);
        int index=0;
        int offset=startIndex;
        for (int count=0; count < size; count++) {
          if (index >= rowsSize) {
            break;
          }
 else           if ((offset + index) >= rowsSize) {
            offset=index * -1;
          }
          AbstractRecord row=parentRows.get(offset + index);
          if (row != null) {
            Object foreignKey=extractBatchKeyFromRow(row,session);
            if (foreignKey == null) {
              count--;
            }
 else {
              cachedObject=checkCacheForBatchKey(row,foreignKey,batchedObjects,batchQuery,originalQuery,session);
              if (cachedObject != null) {
                count--;
              }
 else {
                if (foreignKeys.contains(foreignKey)) {
                  count--;
                }
 else {
                  Object[] key=((CacheId)foreignKey).getPrimaryKey();
                  Object foreignKeyValue=key[0];
                  if (key.length > 1) {
                    foreignKeyValue=Arrays.asList(key);
                  }
                  foreignKeyValues.add(foreignKeyValue);
                  foreignKeys.add(foreignKey);
                }
              }
            }
          }
          index++;
        }
        List<AbstractRecord> remainingParentRows=null;
        if (startIndex == 0) {
          remainingParentRows=new ArrayList(parentRows.subList(index,rowsSize));
        }
 else         if (startIndex == offset) {
          remainingParentRows=new ArrayList(parentRows.subList(0,startIndex - 1));
          remainingParentRows.addAll(parentRows.subList(index,rowsSize));
        }
 else {
          if ((offset + index) >= (startIndex - 1)) {
            remainingParentRows=new ArrayList(0);
          }
 else {
            remainingParentRows=new ArrayList(parentRows.subList(offset + index,startIndex - 1));
          }
        }
        originalPolicy.setDataResults(this,remainingParentRows);
        translationRow=translationRow.clone();
        translationRow.put(QUERY_BATCH_PARAMETER,foreignKeyValues);
        for (        Object foreignKey : foreignKeys) {
          batchedObjects.put(foreignKey,Helper.NULL_VALUE);
        }
      }
 else       if (batchQuery.isReadAllQuery() && ((ReadAllQuery)batchQuery).getBatchFetchPolicy().isIN()) {
        throw QueryException.originalQueryMustUseBatchIN(this,originalQuery);
      }
      executeBatchQuery(batchQuery,parentCacheKey,batchedObjects,session,translationRow);
      batchQuery.setSession(null);
    }
  }
  result=batchedObjects.get(sourceKey);
  if (result == Helper.NULL_VALUE) {
    return null;
  }
 else {
    return result;
  }
}