Program: 70639
Project: 70639
Buggy source:
protected org.eclipse.birt.data.engine.odi.IResultIterator executeOdiQuery(IEventHandler eventHandler,StopSign stopSign) throws DataException {
  if (doesLoadFromCache() == true) {
    DataSourceQuery dsQuery=new DataSourceQuery(dataEngine.getSession());
    JointDataSetQuery jointQuery=(JointDataSetQuery)odiQuery;
    this.prepareCacheQuery(dsQuery);
    dsQuery.setExprProcessor(jointQuery.getExprProcessor());
    List fetchEvents=jointQuery.getFetchEvents();
    if (fetchEvents != null)     for (int i=0; i < fetchEvents.size(); i++)     dsQuery.addOnFetchEvent((IResultObjectEvent)fetchEvents.get(i));
    dsQuery.setMaxRows(jointQuery.getMaxRows());
    dsQuery.setOrdering(toList(jointQuery.getOrdering()));
    dsQuery.setGrouping(toList(jointQuery.getGrouping()));
    return dsQuery.execute(eventHandler,stopSign);
  }
  ResultIterator left=null;
  ResultIterator right=null;
  try {
    DataSetCacheManager dscm=dataEngine.getSession().getDataSetCacheManager();
    dscm.setDataSourceAndDataSet(leftDataSourceDesign,leftDataSetDesgin,leftParameterHints,leftAppContext);
    left=(ResultIterator)leftQueryResults.getResultIterator();
    dscm.setDataSourceAndDataSet(rightDataSourceDesign,rightDataSetDesgin,rightParameterHints,rightAppContext);
    right=(ResultIterator)rightQueryResults.getResultIterator();
  }
 catch (  BirtException e) {
    throw DataException.wrap(e);
  }
  initialize(dataEngine,appContext,left,right);
  JointResultMetadata jrm=getJointResultMetadata(left.getResultMetaData(),right.getResultMetaData());
  resultClass=jrm.getResultClass();
  populator=JointDataSetPopulatorFactory.getBinaryTreeDataSetPopulator(left.getOdiResult(),right.getOdiResult(),jrm,matcher,joinType,dataEngine.getSession(),dataSetDesign.getRowFetchLimit());
  if (doesSaveToCache() == false)   return new CachedResultSet((BaseQuery)this.odiQuery,resultClass,populator,eventHandler,dataEngine.getSession(),stopSign);
 else   return new CachedResultSet((BaseQuery)this.odiQuery,resultClass,new DataSetResultCache(populator,resultClass,dataEngine.getSession()),eventHandler,dataEngine.getSession(),stopSign);
}

Fixed version (ground truth):
protected org.eclipse.birt.data.engine.odi.IResultIterator executeOdiQuery(IEventHandler eventHandler,StopSign stopSign) throws DataException {
  if (doesLoadFromCache() == true) {
    DataSourceQuery dsQuery=new DataSourceQuery(dataEngine.getSession());
    JointDataSetQuery jointQuery=(JointDataSetQuery)odiQuery;
    this.prepareCacheQuery(dsQuery);
    dsQuery.setExprProcessor(jointQuery.getExprProcessor());
    List fetchEvents=jointQuery.getFetchEvents();
    if (fetchEvents != null)     for (int i=0; i < fetchEvents.size(); i++)     dsQuery.addOnFetchEvent((IResultObjectEvent)fetchEvents.get(i));
    dsQuery.setMaxRows(jointQuery.getMaxRows());
    dsQuery.setOrdering(toList(jointQuery.getOrdering()));
    dsQuery.setGrouping(toList(jointQuery.getGrouping()));
    return dsQuery.execute(eventHandler,stopSign);
  }
  ResultIterator left=null;
  ResultIterator right=null;
  try {
    DataSetCacheManager dscm=dataEngine.getSession().getDataSetCacheManager();
    dscm.setDataSourceAndDataSet(leftDataSourceDesign,leftDataSetDesgin,leftParameterHints,leftAppContext);
    left=(ResultIterator)leftQueryResults.getResultIterator();
    dscm.setDataSourceAndDataSet(rightDataSourceDesign,rightDataSetDesgin,rightParameterHints,rightAppContext);
    right=(ResultIterator)rightQueryResults.getResultIterator();
  }
 catch (  BirtException e) {
    throw DataException.wrap(e);
  }
  initialize(dataEngine,appContext,left,right);
  JointResultMetadata jrm=getJointResultMetadata(left.getResultMetaData(),right.getResultMetaData());
  resultClass=jrm.getResultClass();
  populator=JointDataSetPopulatorFactory.getBinaryTreeDataSetPopulator(left.getOdiResult(),right.getOdiResult(),jrm,matcher,joinType,dataEngine.getSession(),dataSetDesign.getRowFetchLimit());
  DataSetCacheManager dscm=dataEngine.getSession().getDataSetCacheManager();
  dscm.setDataSourceAndDataSet(null,dataSetDesign,null,dscm.getCurrentAppContext());
  if (doesSaveToCache() == false)   return new CachedResultSet((BaseQuery)this.odiQuery,resultClass,populator,eventHandler,dataEngine.getSession(),stopSign);
 else   return new CachedResultSet((BaseQuery)this.odiQuery,resultClass,new DataSetResultCache(populator,resultClass,dataEngine.getSession()),eventHandler,dataEngine.getSession(),stopSign);
}