Program: 66416
Project: 66416
Buggy source:
protected org.eclipse.birt.data.engine.odi.IResultIterator executeOdiQuery(IEventHandler eventHandler) 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);
  }
  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,parameterHints,dscm.getCurrentAppContext());
  if (doesSaveToCache() == false)   return new CachedResultSet((BaseQuery)this.odiQuery,resultClass,populator,eventHandler,dataEngine.getSession());
 else   return new CachedResultSet((BaseQuery)this.odiQuery,resultClass,new DataSetToCache(populator,resultClass,dataEngine.getSession()),eventHandler,dataEngine.getSession());
}

Fixed version (ground truth):
protected org.eclipse.birt.data.engine.odi.IResultIterator executeOdiQuery(IEventHandler eventHandler) 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()));
    dsQuery.setQueryDefinition(jointQuery.getQueryDefinition());
    return dsQuery.execute(eventHandler);
  }
  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,parameterHints,dscm.getCurrentAppContext());
  if (doesSaveToCache() == false)   return new CachedResultSet((BaseQuery)this.odiQuery,resultClass,populator,eventHandler,dataEngine.getSession());
 else   return new CachedResultSet((BaseQuery)this.odiQuery,resultClass,new DataSetToCache(populator,resultClass,dataEngine.getSession()),eventHandler,dataEngine.getSession());
}