Program: 67348
Project: 67348
Buggy source:
/** 
 * @param query
 * @param resultMetaList
 * @param levelNameColumnNamePair
 * @param hierHandle
 * @throws BirtException 
 */
private void prepareLevels(QueryDefinition query,TabularHierarchyHandle hierHandle,List metaList,String dimName) throws BirtException {
  try {
    Set<String> columnNamesForLevels=new HashSet<String>();
    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;
      columnNamesForLevels.add(level.getColumnName());
      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(),sessionContext.getDataEngineContext().getTimeZone())),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(),sessionContext.getDataEngineContext().getTimeZone()));
        }
 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(),this.sessionContext.getDataEngineContext().getLocale(),sessionContext.getDataEngineContext().getTimeZone());
          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);
        ExpressionHandle displayExprHandle=level.getExpressionProperty(ITabularLevelModel.DISPLAY_COLUMN_NAME_PROP);
        if (displayExprHandle != null) {
          query.addBinding(new Binding(meta.getName(),modelAdaptor.adaptJSExpression(displayExprHandle.getStringExpression(),displayExprHandle.getType())));
        }
      }
      if (level.getMemberACLExpression() != null && level.getMemberACLExpression().getExpression() != null) {
        String aclExprName=DataSetIterator.createLevelACLName(level.getName());
        IScriptExpression expr=modelAdaptor.adaptExpression((Expression)level.getMemberACLExpression().getValue());
        query.addBinding(new Binding(aclExprName,expr));
        DataSetIterator.ColumnMeta meta=new DataSetIterator.ColumnMeta(aclExprName,null,DataSetIterator.ColumnMeta.UNKNOWN_TYPE);
        metaList.add(meta);
      }
      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()));
      if (ExpressionUtil.getColumnName(exprString) != null) {
        gd.setKeyExpression(exprString);
      }
 else {
        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,String levelColumnName) 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(levelColumnName == null ? level.getColumnName() : levelColumnName);
      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(),sessionContext.getDataEngineContext().getTimeZone())),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(),sessionContext.getDataEngineContext().getTimeZone()));
        }
 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(),this.sessionContext.getDataEngineContext().getLocale(),sessionContext.getDataEngineContext().getTimeZone());
          bindingExpr=ExpressionUtil.createJSDataSetRowExpression(levelColumnName == null ? level.getColumnName() : levelColumnName);
        }
 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);
        ExpressionHandle displayExprHandle=level.getExpressionProperty(ITabularLevelModel.DISPLAY_COLUMN_NAME_PROP);
        if (displayExprHandle != null) {
          query.addBinding(new Binding(meta.getName(),modelAdaptor.adaptJSExpression(displayExprHandle.getStringExpression(),displayExprHandle.getType())));
        }
      }
      if (level.getMemberACLExpression() != null && level.getMemberACLExpression().getExpression() != null) {
        String aclExprName=DataSetIterator.createLevelACLName(level.getName());
        IScriptExpression expr=modelAdaptor.adaptExpression((Expression)level.getMemberACLExpression().getValue());
        query.addBinding(new Binding(aclExprName,expr));
        DataSetIterator.ColumnMeta meta=new DataSetIterator.ColumnMeta(aclExprName,null,DataSetIterator.ColumnMeta.UNKNOWN_TYPE);
        metaList.add(meta);
      }
      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()));
      if (ExpressionUtil.getColumnName(exprString) != null) {
        gd.setKeyExpression(exprString);
      }
 else {
        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);
  }
}