Program: 66414
Project: 66414
Buggy source:
/** 
 * @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()) {
    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)) {
        FilterDefinition filter=buildFilterForTimeDimension(dim,hier);
        if (filter != null)         query.addFilter(filter);
      }
      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=createDimensionQuery(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);
          }
        }
        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]));
}

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()) {
    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) {
      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=createDimensionQuery(this,hier,metaList,String.valueOf(cubeHandle.getElement().getID()));
      if (CubeHandleUtil.isTimeDimension(dim)) {
        FilterDefinition filter=buildFilterForTimeDimension(dim,hier);
        if (filter != null)         query.addFilter(filter);
      }
      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);
          }
        }
        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]));
}