Program: 66701
Project: 66701
Buggy source:
protected IResultIterator executeOdiQuery(IEventHandler eventHandler) throws DataException {
  try {
    RDLoad rdLoad=RDUtil.newLoad(engine.getSession().getTempDir(),getEngineContext(),new QueryResultInfo(realBasedQueryID,null,-1));
    DataSetResultSet dataSetResult=rdLoad.loadDataSetData(null,null,new HashMap());
    StreamManager manager=new StreamManager(getEngineContext(),new QueryResultInfo(queryDefn.getQueryResultsID(),null,0));
    if (PLSUtil.isPLSEnabled(queryDefn)) {
      if (PLSUtil.needUpdateDataSet(queryDefn,manager)) {
        if (getEngineContext().getDocWriter() != null) {
          populatePLSDataSetData(eventHandler,manager);
          dataSetResult.close();
          rdLoad=RDUtil.newLoad(engine.getSession().getTempDir(),getEngineContext(),new QueryResultInfo(realBasedQueryID,null,-1));
          dataSetResult=rdLoad.loadDataSetData(null,null,null);
        }
 else {
          org.eclipse.birt.data.engine.impl.document.ResultIterator docIt=new org.eclipse.birt.data.engine.impl.document.ResultIterator(engine.getSession().getTempDir(),getEngineContext(),null,queryDefn.getQueryResultsID(),queryDefn);
          PLSEnabledDataSetPopulator populator=new PLSEnabledDataSetPopulator(queryDefn,queryDefn.getQueryExecutionHints().getTargetGroupInstances(),docIt);
          IResultIterator resultIterator=new CachedResultSet(query,populateResultClass(populator.getResultClass()),populator,eventHandler,engine.getSession());
          dataSetResult.close();
          cleanUpOldRD();
          return resultIterator;
        }
      }
 else {
        cleanUpOldRD();
      }
    }
    IResultClass meta=dataSetResult.getResultClass();
    IResultIterator resultIterator=new CachedResultSet(query,populateResultClass(meta),dataSetResult,eventHandler,engine.getSession());
    dataSetResult.close();
    return resultIterator;
  }
 catch (  IOException e) {
    throw new DataException(e.getLocalizedMessage());
  }
}

Fixed version (ground truth):
protected IResultIterator executeOdiQuery(IEventHandler eventHandler) throws DataException {
  try {
    RDLoad rdLoad=RDUtil.newLoad(engine.getSession().getTempDir(),getEngineContext(),new QueryResultInfo(realBasedQueryID,null,-1));
    DataSetResultSet dataSetResult=rdLoad.loadDataSetData(null,null,new HashMap());
    StreamManager manager=new StreamManager(getEngineContext(),new QueryResultInfo(queryDefn.getQueryResultsID(),null,0));
    if (PLSUtil.isPLSEnabled(queryDefn)) {
      if (PLSUtil.needUpdateDataSet(queryDefn,manager)) {
        if (getEngineContext().getDocWriter() != null) {
          populatePLSDataSetData(eventHandler,manager);
          dataSetResult.close();
          rdLoad=RDUtil.newLoad(engine.getSession().getTempDir(),getEngineContext(),new QueryResultInfo(realBasedQueryID,null,-1));
          dataSetResult=rdLoad.loadDataSetData(null,null,null);
        }
 else {
          org.eclipse.birt.data.engine.impl.document.ResultIterator docIt=null;
          if (queryDefn.isSummaryQuery()) {
            docIt=new org.eclipse.birt.data.engine.impl.document.ResultIterator2(engine.getSession().getTempDir(),getEngineContext(),null,queryDefn.getQueryResultsID(),queryDefn.getGroups().size(),queryDefn.isSummaryQuery(),queryDefn);
          }
 else {
            docIt=new org.eclipse.birt.data.engine.impl.document.ResultIterator(engine.getSession().getTempDir(),getEngineContext(),null,queryDefn.getQueryResultsID(),queryDefn);
          }
          PLSEnabledDataSetPopulator populator=new PLSEnabledDataSetPopulator(queryDefn,queryDefn.getQueryExecutionHints().getTargetGroupInstances(),docIt);
          IResultIterator resultIterator=new CachedResultSet(query,populateResultClass(populator.getResultClass()),populator,eventHandler,engine.getSession());
          dataSetResult.close();
          cleanUpOldRD();
          return resultIterator;
        }
      }
 else {
        cleanUpOldRD();
      }
    }
    IResultClass meta=dataSetResult.getResultClass();
    IResultIterator resultIterator=new CachedResultSet(query,populateResultClass(meta),dataSetResult,eventHandler,engine.getSession());
    dataSetResult.close();
    return resultIterator;
  }
 catch (  IOException e) {
    throw new DataException(e.getLocalizedMessage());
  }
}