Program: 70160
Project: 70160
Buggy source:
/** 
 * @param query
 * @param resultMetaList
 * @param levelNameColumnNamePair
 * @param hierHandle
 * @throws AdapterException
 */
private static void prepareLevels(QueryDefinition query,TabularHierarchyHandle hierHandle,List metaList,String dimName) throws AdapterException {
  try {
    List levels=hierHandle.getContents(TabularHierarchyHandle.LEVELS_PROP);
    for (int j=0; j < levels.size(); j++) {
      TabularLevelHandle level=(TabularLevelHandle)levels.get(j);
      DataSetIterator.ColumnMeta temp=null;
      String exprString=ExpressionUtil.createJSDataSetRowExpression(level.getColumnName());
      int type=DataAdapterUtil.adaptModelDataType(level.getDataType());
      if (type == DataType.UNKNOWN_TYPE || type == DataType.ANY_TYPE)       type=DataType.STRING_TYPE;
      if (level.getDateTimeLevelType() != null) {
        temp=new DataSetIterator.ColumnMeta(DataSetIterator.createLevelName(dimName,level.getName()),new DataSetIterator.DataProcessorWrapper(GroupCalculatorFactory.getGroupCalculator(IGroupDefinition.NUMERIC_INTERVAL,DataType.INTEGER_TYPE,String.valueOf(DataSetIterator.getDefaultStartValue(level.getDateTimeLevelType(),level.getIntervalBase())),level.getIntervalRange())),DataSetIterator.ColumnMeta.LEVEL_KEY_TYPE);
        temp.setDataType(DataType.INTEGER_TYPE);
        exprString=DataSetIterator.createDateTransformerExpr(level.getDateTimeLevelType(),exprString);
      }
 else {
        IDataProcessor processor=null;
        if (DesignChoiceConstants.LEVEL_TYPE_DYNAMIC.equals(level.getLevelType())) {
          int interval=GroupAdapter.intervalFromModel(level.getInterval());
          if (interval != IGroupDefinition.NO_INTERVAL)           processor=new DataSetIterator.DataProcessorWrapper(GroupCalculatorFactory.getGroupCalculator(interval,type,level.getIntervalBase(),level.getIntervalRange()));
        }
 else         if (DesignChoiceConstants.LEVEL_TYPE_MIRRORED.equals(level.getLevelType())) {
          Iterator it=level.staticValuesIterator();
          List dispExpr=new ArrayList();
          List filterExpr=new ArrayList();
          while (it.hasNext()) {
            RuleHandle o=(RuleHandle)it.next();
            dispExpr.add(o.getDisplayExpression());
            filterExpr.add(o.getRuleExpression());
          }
          exprString="String_Node_Str";
          if (level.getDefaultValue() != null) {
            exprString+="String_Node_Str" + JavascriptEvalUtil.transformToJsConstants(level.getDefaultValue()) + "String_Node_Str";
          }
          for (int i=0; i < dispExpr.size(); i++) {
            String disp="String_Node_Str" + JavascriptEvalUtil.transformToJsConstants(String.valueOf(dispExpr.get(i))) + "String_Node_Str";
            String filter=String.valueOf(filterExpr.get(i));
            exprString+="String_Node_Str" + filter + "String_Node_Str"+ disp+ "String_Node_Str";
          }
        }
        temp=new DataSetIterator.ColumnMeta(DataSetIterator.createLevelName(dimName,level.getName()),processor,DataSetIterator.ColumnMeta.LEVEL_KEY_TYPE);
        temp.setDataType(type);
      }
      metaList.add(temp);
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        IDataProcessor processor=null;
        String bindingExpr=null;
        if (level.getDateTimeLevelType() != null && DataSetIterator.DATE_TIME_ATTR_NAME.equals(levelAttr.getName())) {
          processor=new DataSetIterator.DateTimeAttributeProcessor(level.getDateTimeLevelType());
          bindingExpr=ExpressionUtil.createJSDataSetRowExpression(level.getColumnName());
        }
 else {
          bindingExpr=ExpressionUtil.createJSDataSetRowExpression(levelAttr.getName());
        }
        DataSetIterator.ColumnMeta meta=new DataSetIterator.ColumnMeta(DataSetIterator.createLevelName(dimName,OlapExpressionUtil.getAttributeColumnName(level.getName(),levelAttr.getName())),processor,DataSetIterator.ColumnMeta.UNKNOWN_TYPE);
        meta.setDataType(DataAdapterUtil.adaptModelDataType(levelAttr.getDataType()));
        metaList.add(meta);
        query.addBinding(new Binding(meta.getName(),new ScriptExpression(bindingExpr)));
      }
      if (DesignChoiceConstants.LEVEL_TYPE_DYNAMIC.equals(level.getLevelType()) && level.getDisplayColumnName() != null) {
        DataSetIterator.ColumnMeta meta=new DataSetIterator.ColumnMeta(DataSetIterator.createLevelName(dimName,OlapExpressionUtil.getDisplayColumnName(level.getName())),null,DataSetIterator.ColumnMeta.UNKNOWN_TYPE);
        meta.setDataType(DataType.STRING_TYPE);
        metaList.add(meta);
        query.addBinding(new Binding(meta.getName(),new ScriptExpression(level.getDisplayColumnName())));
      }
      String levelName=DataSetIterator.createLevelName(dimName,level.getName());
      query.addBinding(new Binding(levelName,new ScriptExpression(exprString,type)));
      GroupDefinition gd=new GroupDefinition(String.valueOf(query.getGroups().size()));
      gd.setKeyExpression(ExpressionUtil.createJSRowExpression(levelName));
      if (level.getLevelType() != null && level.getDateTimeLevelType() == null) {
        gd.setIntervalRange(level.getIntervalRange());
        gd.setIntervalStart(level.getIntervalBase());
        gd.setInterval(GroupAdapter.intervalFromModel(level.getInterval()));
      }
      if (level.getDateTimeLevelType() != null) {
        gd.setIntervalRange(level.getIntervalRange() == 0 ? 1 : level.getIntervalRange());
        gd.setIntervalStart(String.valueOf(DataSetIterator.getDefaultStartValue(level.getDateTimeLevelType(),level.getIntervalBase())));
        gd.setInterval(IGroupDefinition.NUMERIC_INTERVAL);
      }
      query.addGroup(gd);
    }
  }
 catch (  DataException e) {
    throw new AdapterException(e.getLocalizedMessage(),e);
  }
}

Fixed version (ground truth):
/** 
 * @param query
 * @param resultMetaList
 * @param levelNameColumnNamePair
 * @param hierHandle
 * @throws BirtException 
 */
private void prepareLevels(QueryDefinition query,TabularHierarchyHandle hierHandle,List metaList,String dimName) throws BirtException {
  try {
    List levels=hierHandle.getContents(TabularHierarchyHandle.LEVELS_PROP);
    for (int j=0; j < levels.size(); j++) {
      TabularLevelHandle level=(TabularLevelHandle)levels.get(j);
      DataSetIterator.ColumnMeta temp=null;
      String exprString=ExpressionUtil.createJSDataSetRowExpression(level.getColumnName());
      int type=DataAdapterUtil.adaptModelDataType(level.getDataType());
      if (type == DataType.UNKNOWN_TYPE || type == DataType.ANY_TYPE)       type=DataType.STRING_TYPE;
      if (level.getDateTimeLevelType() != null) {
        temp=new DataSetIterator.ColumnMeta(DataSetIterator.createLevelName(dimName,level.getName()),new DataSetIterator.DataProcessorWrapper(GroupCalculatorFactory.getGroupCalculator(IGroupDefinition.NUMERIC_INTERVAL,DataType.INTEGER_TYPE,String.valueOf(DataSetIterator.getDefaultStartValue(level.getDateTimeLevelType(),level.getIntervalBase())),level.getIntervalRange(),sessionContext.getDataEngineContext().getLocale())),DataSetIterator.ColumnMeta.LEVEL_KEY_TYPE);
        temp.setDataType(DataType.INTEGER_TYPE);
        exprString=DataSetIterator.createDateTransformerExpr(level.getDateTimeLevelType(),exprString);
      }
 else {
        IDataProcessor processor=null;
        if (DesignChoiceConstants.LEVEL_TYPE_DYNAMIC.equals(level.getLevelType())) {
          int interval=GroupAdapter.intervalFromModel(level.getInterval());
          if (interval != IGroupDefinition.NO_INTERVAL)           processor=new DataSetIterator.DataProcessorWrapper(GroupCalculatorFactory.getGroupCalculator(interval,type,level.getIntervalBase(),level.getIntervalRange(),sessionContext.getDataEngineContext().getLocale()));
        }
 else         if (DesignChoiceConstants.LEVEL_TYPE_MIRRORED.equals(level.getLevelType())) {
          Iterator it=level.staticValuesIterator();
          List dispExpr=new ArrayList();
          List filterExpr=new ArrayList();
          while (it.hasNext()) {
            RuleHandle o=(RuleHandle)it.next();
            dispExpr.add(o.getDisplayExpression());
            filterExpr.add(o.getRuleExpression());
          }
          exprString="String_Node_Str";
          if (level.getDefaultValue() != null) {
            exprString+="String_Node_Str" + JavascriptEvalUtil.transformToJsConstants(level.getDefaultValue()) + "String_Node_Str";
          }
          for (int i=0; i < dispExpr.size(); i++) {
            String disp="String_Node_Str" + JavascriptEvalUtil.transformToJsConstants(String.valueOf(dispExpr.get(i))) + "String_Node_Str";
            String filter=String.valueOf(filterExpr.get(i));
            exprString+="String_Node_Str" + filter + "String_Node_Str"+ disp+ "String_Node_Str";
          }
        }
        temp=new DataSetIterator.ColumnMeta(DataSetIterator.createLevelName(dimName,level.getName()),processor,DataSetIterator.ColumnMeta.LEVEL_KEY_TYPE);
        temp.setDataType(type);
      }
      metaList.add(temp);
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        IDataProcessor processor=null;
        String bindingExpr=null;
        if (level.getDateTimeLevelType() != null && DataSetIterator.DATE_TIME_ATTR_NAME.equals(levelAttr.getName())) {
          processor=new DataSetIterator.DateTimeAttributeProcessor(level.getDateTimeLevelType());
          bindingExpr=ExpressionUtil.createJSDataSetRowExpression(level.getColumnName());
        }
 else {
          bindingExpr=ExpressionUtil.createJSDataSetRowExpression(levelAttr.getName());
        }
        DataSetIterator.ColumnMeta meta=new DataSetIterator.ColumnMeta(DataSetIterator.createLevelName(dimName,OlapExpressionUtil.getAttributeColumnName(level.getName(),levelAttr.getName())),processor,DataSetIterator.ColumnMeta.UNKNOWN_TYPE);
        meta.setDataType(DataAdapterUtil.adaptModelDataType(levelAttr.getDataType()));
        metaList.add(meta);
        query.addBinding(new Binding(meta.getName(),new ScriptExpression(bindingExpr)));
      }
      if (DesignChoiceConstants.LEVEL_TYPE_DYNAMIC.equals(level.getLevelType()) && level.getDisplayColumnName() != null) {
        DataSetIterator.ColumnMeta meta=new DataSetIterator.ColumnMeta(DataSetIterator.createLevelName(dimName,OlapExpressionUtil.getDisplayColumnName(level.getName())),null,DataSetIterator.ColumnMeta.UNKNOWN_TYPE);
        meta.setDataType(DataType.STRING_TYPE);
        metaList.add(meta);
        query.addBinding(new Binding(meta.getName(),new ScriptExpression(level.getDisplayColumnName())));
      }
      String levelName=DataSetIterator.createLevelName(dimName,level.getName());
      query.addBinding(new Binding(levelName,new ScriptExpression(exprString,type)));
      GroupDefinition gd=new GroupDefinition(String.valueOf(query.getGroups().size()));
      gd.setKeyExpression(ExpressionUtil.createJSRowExpression(levelName));
      if (level.getLevelType() != null && level.getDateTimeLevelType() == null) {
        gd.setIntervalRange(level.getIntervalRange());
        gd.setIntervalStart(level.getIntervalBase());
        gd.setInterval(GroupAdapter.intervalFromModel(level.getInterval()));
      }
      if (level.getDateTimeLevelType() != null) {
        gd.setIntervalRange(level.getIntervalRange() == 0 ? 1 : level.getIntervalRange());
        gd.setIntervalStart(String.valueOf(DataSetIterator.getDefaultStartValue(level.getDateTimeLevelType(),level.getIntervalBase())));
        gd.setInterval(IGroupDefinition.NUMERIC_INTERVAL);
      }
      query.addGroup(gd);
    }
  }
 catch (  DataException e) {
    throw new AdapterException(e.getLocalizedMessage(),e);
  }
}