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

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