Program: 73068
Project: 73068
Buggy source:
private IExtractionResults extractByInstanceID(InstanceID instanceId) throws BirtException {
  InstanceID iid=instanceId;
  while (iid != null) {
    long id=iid.getComponentID();
    ReportItemDesign design=(ReportItemDesign)report.getReportItemByID(id);
    IDataQueryDefinition dataQuery=design.getQuery();
    if (dataQuery != null) {
      if (!(dataQuery instanceof IBaseQueryDefinition)) {
        return null;
      }
      IBaseQueryDefinition query=(IBaseQueryDefinition)dataQuery;
      String queryId=(String)query2QueryIdMapping.get(query);
      if (filterExpressions != null) {
        query=cloneQuery(query);
        for (int i=0; i < filterExpressions.length; i++) {
          query.getFilters().add(filterExpressions[i]);
        }
        filterExpressions=null;
      }
      if (sortExpressions != null) {
        query=cloneQuery(query);
        for (int i=0; i < sortExpressions.length; i++) {
          query.getSorts().add(sortExpressions[i]);
        }
        sortExpressions=null;
      }
      if (maxRows != -1) {
        query.setMaxRows(maxRows);
        maxRows=-1;
      }
      if (query instanceof IQueryDefinition) {
        while (iid != null) {
          DataID dataId=iid.getDataID();
          if (dataId != null) {
            DataSetID dataSetId=dataId.getDataSetID();
            long rowId=dataId.getRowID();
            IResultIterator dataIter=executeQuery(dataSetId.toString(),rowId,queryId,(IQueryDefinition)query);
            IResultMetaData metaData=getMetaDateByInstanceID(instanceId);
            if (dataIter != null && metaData != null) {
              return new ExtractionResults(dataIter,metaData,this.selectedColumns);
            }
            return null;
          }
          iid=iid.getParentID();
        }
        IResultIterator dataIter=executeQuery(null,-1,queryId,(QueryDefinition)query);
        IResultMetaData metaData=getMetaDateByInstanceID(instanceId);
        if (dataIter != null && metaData != null) {
          return new ExtractionResults(dataIter,metaData,this.selectedColumns);
        }
        return null;
      }
 else {
        while (iid != null) {
          DataID dataId=iid.getDataID();
          if (dataId != null) {
            DataSetID dataSetId=dataId.getDataSetID();
            long rowId=dataId.getRowID();
            IResultIterator dataIter=executeSubQuery(dataSetId,rowId,(ISubqueryDefinition)query);
            IResultMetaData metaData=getMetaDateByInstanceID(instanceId);
            if (dataIter != null && metaData != null) {
              return new ExtractionResults(dataIter,metaData,this.selectedColumns);
            }
            return null;
          }
          iid=iid.getParentID();
        }
      }
    }
    iid=iid.getParentID();
  }
  return null;
}

Fixed version (ground truth):
private IExtractionResults extractByInstanceID(InstanceID instanceId) throws BirtException {
  InstanceID iid=instanceId;
  while (iid != null) {
    long id=iid.getComponentID();
    ReportItemDesign design=(ReportItemDesign)report.getReportItemByID(id);
    IDataQueryDefinition dataQuery=design.getQuery();
    if (dataQuery != null) {
      if (!(dataQuery instanceof IBaseQueryDefinition)) {
        return null;
      }
      IBaseQueryDefinition query=(IBaseQueryDefinition)dataQuery;
      String queryId=(String)query2QueryIdMapping.get(query);
      if (filterExpressions != null) {
        query=cloneQuery(query);
        for (int i=0; i < filterExpressions.length; i++) {
          query.getFilters().add(filterExpressions[i]);
        }
        filterExpressions=null;
      }
      if (sortExpressions != null) {
        query=cloneQuery(query);
        for (int i=0; i < sortExpressions.length; i++) {
          query.getSorts().add(sortExpressions[i]);
        }
        sortExpressions=null;
      }
      if (query instanceof IQueryDefinition) {
        while (iid != null) {
          DataID dataId=iid.getDataID();
          if (dataId != null) {
            DataSetID dataSetId=dataId.getDataSetID();
            long rowId=dataId.getRowID();
            IResultIterator dataIter=executeQuery(dataSetId.toString(),rowId,queryId,(IQueryDefinition)query);
            IResultMetaData metaData=getMetaDateByInstanceID(instanceId);
            if (dataIter != null && metaData != null) {
              return new ExtractionResults(dataIter,metaData,this.selectedColumns,startRow,maxRows);
            }
            return null;
          }
          iid=iid.getParentID();
        }
        IResultIterator dataIter=executeQuery(null,-1,queryId,(QueryDefinition)query);
        IResultMetaData metaData=getMetaDateByInstanceID(instanceId);
        if (dataIter != null && metaData != null) {
          return new ExtractionResults(dataIter,metaData,this.selectedColumns,startRow,maxRows);
        }
        return null;
      }
 else {
        while (iid != null) {
          DataID dataId=iid.getDataID();
          if (dataId != null) {
            DataSetID dataSetId=dataId.getDataSetID();
            long rowId=dataId.getRowID();
            IResultIterator dataIter=executeSubQuery(dataSetId,rowId,(ISubqueryDefinition)query);
            IResultMetaData metaData=getMetaDateByInstanceID(instanceId);
            if (dataIter != null && metaData != null) {
              return new ExtractionResults(dataIter,metaData,this.selectedColumns,startRow,maxRows);
            }
            return null;
          }
          iid=iid.getParentID();
        }
      }
    }
    iid=iid.getParentID();
  }
  return null;
}