Program: 67075
Project: 67075
Buggy source:
/** 
 * @param cubeHandle
 * @throws BirtException 
 */
private void prepareForCubeGeneration(TabularCubeHandle cubeHandle,Map<ReportElementHandle,QueryDefinition> queryMap,Map<ReportElementHandle,List<ColumnMeta>> metaMap) throws BirtException {
  List<IQueryDefinition> queryDefns=new ArrayList<IQueryDefinition>();
  List<ColumnMeta> metaList=new ArrayList<ColumnMeta>();
  QueryDefinition query=createQuery(this,cubeHandle,metaList);
  if (cubeHandle.autoPrimaryKey()) {
    for (    Object o : query.getGroups()) {
      IGroupDefinition gd=(IGroupDefinition)o;
      SortDefinition sd=new SortDefinition();
      sd.setExpression(gd.getKeyExpression());
      query.getSorts().add(sd);
    }
    query.setUsesDetails(true);
    query.getGroups().clear();
  }
  queryDefns.add(query);
  queryMap.put(cubeHandle,query);
  metaMap.put(cubeHandle,metaList);
  List<DimensionHandle> dimHandles=cubeHandle.getContents(CubeHandle.DIMENSIONS_PROP);
  for (  DimensionHandle dim : dimHandles) {
    List<TabularHierarchyHandle> hiers=dim.getContents(DimensionHandle.HIERARCHIES_PROP);
    for (    TabularHierarchyHandle hier : hiers) {
      if (CubeHandleUtil.isTimeDimension(dim))       continue;
      String columnForDeepestLevel=null;
      List levels=hier.getContents(TabularHierarchyHandle.LEVELS_PROP);
      if (levels.size() >= 1) {
        TabularLevelHandle level=(TabularLevelHandle)levels.get(levels.size() - 1);
        columnForDeepestLevel=level.getColumnName();
      }
      metaList=new ArrayList<ColumnMeta>();
      query=createQuery(this,hier,metaList,String.valueOf(cubeHandle.getElement().getID()));
      String[] jointHierarchyKeys=getJointHierarchyKeys(cubeHandle,hier);
      if (cubeHandle.autoPrimaryKey() && jointHierarchyKeys.length > 0) {
        if (!Arrays.deepEquals(jointHierarchyKeys,new String[]{columnForDeepestLevel})) {
          for (          String key : jointHierarchyKeys) {
            String exprString=ExpressionUtil.createJSDataSetRowExpression(key);
            query.addBinding(new Binding(getDummyLevelNameForJointHierarchyKey(key),new ScriptExpression(exprString)));
            DataSetIterator.ColumnMeta temp=new DataSetIterator.ColumnMeta(getDummyLevelNameForJointHierarchyKey(key),null,DataSetIterator.ColumnMeta.LEVEL_KEY_TYPE);
            temp.setDataType(getColumnDataType(hier.getDataSet(),key));
            metaList.add(temp);
          }
        }
        for (        Object o : query.getGroups()) {
          IGroupDefinition gd=(IGroupDefinition)o;
          SortDefinition sd=new SortDefinition();
          sd.setExpression(gd.getKeyExpression());
          query.getSorts().add(sd);
        }
        query.setUsesDetails(true);
        query.getGroups().clear();
      }
      queryDefns.add(query);
      queryMap.put(hier,query);
      metaMap.put(hier,metaList);
    }
  }
  this.dataEngine.registerQueries(queryDefns.toArray(new IDataQueryDefinition[0]));
}

Fixed version (ground truth):
/** 
 * @param cubeHandle
 * @throws BirtException 
 */
private void prepareForCubeGeneration(CubeHandle cHandle) throws BirtException {
  TabularCubeHandle cubeHandle=null;
  if (cHandle instanceof TabularCubeHandle) {
    cubeHandle=(TabularCubeHandle)cHandle;
  }
  List<IQueryDefinition> queryDefns=new ArrayList<IQueryDefinition>();
  List<ColumnMeta> metaList=new ArrayList<ColumnMeta>();
  QueryDefinition query=createQuery(this,cubeHandle,metaList);
  if (cubeHandle.autoPrimaryKey()) {
    for (    Object o : query.getGroups()) {
      IGroupDefinition gd=(IGroupDefinition)o;
      SortDefinition sd=new SortDefinition();
      sd.setExpression(gd.getKeyExpression());
      query.getSorts().add(sd);
    }
    query.setUsesDetails(true);
    query.getGroups().clear();
  }
  queryDefns.add(query);
  cubeQueryMap.put(cubeHandle,query);
  cubeMetaMap.put(cubeHandle,metaList);
  List<DimensionHandle> dimHandles=cubeHandle.getContents(CubeHandle.DIMENSIONS_PROP);
  for (  DimensionHandle dim : dimHandles) {
    List<TabularHierarchyHandle> hiers=dim.getContents(DimensionHandle.HIERARCHIES_PROP);
    for (    TabularHierarchyHandle hier : hiers) {
      if (CubeHandleUtil.isTimeDimension(dim))       continue;
      String columnForDeepestLevel=null;
      List levels=hier.getContents(TabularHierarchyHandle.LEVELS_PROP);
      if (levels.size() >= 1) {
        TabularLevelHandle level=(TabularLevelHandle)levels.get(levels.size() - 1);
        columnForDeepestLevel=level.getColumnName();
      }
      metaList=new ArrayList<ColumnMeta>();
      query=createQuery(this,hier,metaList,String.valueOf(cubeHandle.getElement().getID()));
      String[] jointHierarchyKeys=getJointHierarchyKeys(cubeHandle,hier);
      if (cubeHandle.autoPrimaryKey() && jointHierarchyKeys.length > 0) {
        if (!Arrays.deepEquals(jointHierarchyKeys,new String[]{columnForDeepestLevel})) {
          for (          String key : jointHierarchyKeys) {
            String exprString=ExpressionUtil.createJSDataSetRowExpression(key);
            query.addBinding(new Binding(getDummyLevelNameForJointHierarchyKey(key),new ScriptExpression(exprString)));
            DataSetIterator.ColumnMeta temp=new DataSetIterator.ColumnMeta(getDummyLevelNameForJointHierarchyKey(key),null,DataSetIterator.ColumnMeta.LEVEL_KEY_TYPE);
            temp.setDataType(getColumnDataType(hier.getDataSet(),key));
            metaList.add(temp);
          }
        }
        for (        Object o : query.getGroups()) {
          IGroupDefinition gd=(IGroupDefinition)o;
          SortDefinition sd=new SortDefinition();
          sd.setExpression(gd.getKeyExpression());
          query.getSorts().add(sd);
        }
        query.setUsesDetails(true);
        query.getGroups().clear();
      }
      queryDefns.add(query);
      cubeQueryMap.put(hier,query);
      cubeMetaMap.put(hier,metaList);
    }
  }
  this.dataEngine.registerQueries(queryDefns.toArray(new IDataQueryDefinition[0]));
}