Program: 73488
Project: 73488
Buggy source:
private ISubCubeQueryDefinition createSubCubeQuery() throws BirtException {
  String queryName="String_Node_Str";
  CrosstabReportItemHandle xtab=ChartXTabUtil.getXtabContainerCell(handle).getCrosstab();
  LevelViewHandle levelColumn=ChartXTabUtil.getLevel(xtab,ICrosstabConstants.COLUMN_AXIS_TYPE,0);
  LevelViewHandle levelRow=ChartXTabUtil.getLevel(xtab,ICrosstabConstants.ROW_AXIS_TYPE,0);
  if (cm instanceof ChartWithAxes) {
    if (((ChartWithAxes)cm).isTransposed()) {
      int rowLevelCount=ChartXTabUtil.getLevelCount(xtab,ICrosstabConstants.ROW_AXIS_TYPE);
      if (levelColumn != null) {
        ISubCubeQueryDefinition subCubeQuery=ChartXTabUtil.getCubeElementFactory().createSubCubeQuery(queryName);
        subCubeQuery.setStartingLevelOnColumn(ChartXTabUtil.createDimensionExpression(levelColumn.getCubeLevel()));
        if (levelRow != null && rowLevelCount > 1) {
          subCubeQuery.setStartingLevelOnRow(ChartXTabUtil.createDimensionExpression(levelRow.getCubeLevel()));
        }
        return subCubeQuery;
      }
 else       if (rowLevelCount > 1) {
        ISubCubeQueryDefinition subCubeQuery=ChartXTabUtil.getCubeElementFactory().createSubCubeQuery(queryName);
        subCubeQuery.setStartingLevelOnRow(ChartXTabUtil.createDimensionExpression(levelRow.getCubeLevel()));
        return subCubeQuery;
      }
    }
 else {
      int columnLevelCount=ChartXTabUtil.getLevelCount(xtab,ICrosstabConstants.COLUMN_AXIS_TYPE);
      if (levelRow != null) {
        ISubCubeQueryDefinition subCubeQuery=ChartXTabUtil.getCubeElementFactory().createSubCubeQuery(queryName);
        subCubeQuery.setStartingLevelOnRow(ChartXTabUtil.createDimensionExpression(levelRow.getCubeLevel()));
        if (levelColumn != null && columnLevelCount > 1) {
          subCubeQuery.setStartingLevelOnColumn(ChartXTabUtil.createDimensionExpression(levelColumn.getCubeLevel()));
        }
        return subCubeQuery;
      }
 else       if (columnLevelCount > 1) {
        ISubCubeQueryDefinition subCubeQuery=ChartXTabUtil.getCubeElementFactory().createSubCubeQuery(queryName);
        subCubeQuery.setStartingLevelOnColumn(ChartXTabUtil.createDimensionExpression(levelColumn.getCubeLevel()));
        return subCubeQuery;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
private ISubCubeQueryDefinition createSubCubeQuery() throws BirtException {
  String queryName=ChartReportItemConstants.CHART_SUBQUERY;
  AggregationCellHandle containerCell=ChartXTabUtil.getXtabContainerCell(handle);
  if (containerCell == null) {
    return null;
  }
  CrosstabReportItemHandle xtab=containerCell.getCrosstab();
  LevelViewHandle levelColumn=ChartXTabUtil.getLevel(xtab,ICrosstabConstants.COLUMN_AXIS_TYPE,0);
  LevelViewHandle levelRow=ChartXTabUtil.getLevel(xtab,ICrosstabConstants.ROW_AXIS_TYPE,0);
  if (cm instanceof ChartWithAxes) {
    if (((ChartWithAxes)cm).isTransposed()) {
      int rowLevelCount=ChartXTabUtil.getLevelCount(xtab,ICrosstabConstants.ROW_AXIS_TYPE);
      if (levelColumn != null) {
        ISubCubeQueryDefinition subCubeQuery=ChartXTabUtil.getCubeElementFactory().createSubCubeQuery(queryName);
        subCubeQuery.setStartingLevelOnColumn(ChartXTabUtil.createDimensionExpression(levelColumn.getCubeLevel()));
        if (levelRow != null && rowLevelCount > 1) {
          subCubeQuery.setStartingLevelOnRow(ChartXTabUtil.createDimensionExpression(levelRow.getCubeLevel()));
        }
        return subCubeQuery;
      }
 else       if (rowLevelCount > 1) {
        ISubCubeQueryDefinition subCubeQuery=ChartXTabUtil.getCubeElementFactory().createSubCubeQuery(queryName);
        subCubeQuery.setStartingLevelOnRow(ChartXTabUtil.createDimensionExpression(levelRow.getCubeLevel()));
        return subCubeQuery;
      }
    }
 else {
      int columnLevelCount=ChartXTabUtil.getLevelCount(xtab,ICrosstabConstants.COLUMN_AXIS_TYPE);
      if (levelRow != null) {
        ISubCubeQueryDefinition subCubeQuery=ChartXTabUtil.getCubeElementFactory().createSubCubeQuery(queryName);
        subCubeQuery.setStartingLevelOnRow(ChartXTabUtil.createDimensionExpression(levelRow.getCubeLevel()));
        if (levelColumn != null && columnLevelCount > 1) {
          subCubeQuery.setStartingLevelOnColumn(ChartXTabUtil.createDimensionExpression(levelColumn.getCubeLevel()));
        }
        return subCubeQuery;
      }
 else       if (columnLevelCount > 1) {
        ISubCubeQueryDefinition subCubeQuery=ChartXTabUtil.getCubeElementFactory().createSubCubeQuery(queryName);
        subCubeQuery.setStartingLevelOnColumn(ChartXTabUtil.createDimensionExpression(levelColumn.getCubeLevel()));
        return subCubeQuery;
      }
    }
  }
  return null;
}