Program: 75372
Project: 75372
Buggy source:
/** 
 * @param query
 * @param resultMetaList
 * @param levelNameColumnNamePair
 * @param hierHandle
 * @throws AdapterException
 */
private 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);
      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 ColumnMeta(createLevelName(dimName,level.getName()),new DataProcessorWrapper(GroupCalculatorFactory.getGroupCalculator(IGroupDefinition.NUMERIC_INTERVAL,DataType.INTEGER_TYPE,String.valueOf(getDefaultStartValue(level.getDateTimeLevelType(),level.getIntervalBase())),level.getIntervalRange())),ColumnMeta.LEVEL_KEY_TYPE);
        temp.setDataType(DataType.INTEGER_TYPE);
        exprString=this.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 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";
          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 ColumnMeta(createLevelName(dimName,level.getName()),processor,ColumnMeta.LEVEL_KEY_TYPE);
        temp.setDataType(type);
      }
      metaList.add(temp);
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        ColumnMeta meta=new ColumnMeta(createLevelName(dimName,OlapExpressionUtil.getAttributeColumnName(level.getName(),levelAttr.getName())),null,ColumnMeta.UNKNOWN_TYPE);
        meta.setDataType(DataAdapterUtil.adaptModelDataType(levelAttr.getDataType()));
        metaList.add(meta);
        query.addBinding(new Binding(meta.getName(),new ScriptExpression(ExpressionUtil.createJSDataSetRowExpression(levelAttr.getName()))));
      }
      if (level.getDisplayColumnName() != null) {
        ColumnMeta meta=new ColumnMeta(createLevelName(dimName,OlapExpressionUtil.getDisplayColumnName(level.getName())),null,ColumnMeta.UNKNOWN_TYPE);
        meta.setDataType(DataType.STRING_TYPE);
        metaList.add(meta);
        query.addBinding(new Binding(meta.getName(),new ScriptExpression(level.getDisplayColumnName())));
      }
      String levelName=createLevelName(dimName,level.getName());
      query.addBinding(new Binding(levelName,new ScriptExpression(exprString)));
      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(getDefaultStartValue(level.getDateTimeLevelType(),level.getIntervalBase())));
        gd.setInterval(IGroupDefinition.NUMERIC_INTERVAL);
      }
      query.addGroup(gd);
    }
  }
 catch (  DataException e) {
    throw new AdapterException(e.getLocalizedMessage());
  }
}

Fixed version (ground truth):
/** 
 * @param query
 * @param resultMetaList
 * @param levelNameColumnNamePair
 * @param hierHandle
 * @throws AdapterException
 */
private 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);
      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 ColumnMeta(createLevelName(dimName,level.getName()),new DataProcessorWrapper(GroupCalculatorFactory.getGroupCalculator(IGroupDefinition.NUMERIC_INTERVAL,DataType.INTEGER_TYPE,String.valueOf(getDefaultStartValue(level.getDateTimeLevelType(),level.getIntervalBase())),level.getIntervalRange())),ColumnMeta.LEVEL_KEY_TYPE);
        temp.setDataType(DataType.INTEGER_TYPE);
        exprString=this.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 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";
          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 ColumnMeta(createLevelName(dimName,level.getName()),processor,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 && DATE_TIME_ATTR_NAME.equals(levelAttr.getName())) {
          processor=new DateTimeAttributeProcessor(level.getDateTimeLevelType());
          bindingExpr=ExpressionUtil.createJSDataSetRowExpression(level.getColumnName());
        }
 else {
          bindingExpr=ExpressionUtil.createJSDataSetRowExpression(levelAttr.getName());
        }
        ColumnMeta meta=new ColumnMeta(createLevelName(dimName,OlapExpressionUtil.getAttributeColumnName(level.getName(),levelAttr.getName())),processor,ColumnMeta.UNKNOWN_TYPE);
        meta.setDataType(DataAdapterUtil.adaptModelDataType(levelAttr.getDataType()));
        metaList.add(meta);
        query.addBinding(new Binding(meta.getName(),new ScriptExpression(bindingExpr)));
      }
      if (level.getDisplayColumnName() != null) {
        ColumnMeta meta=new ColumnMeta(createLevelName(dimName,OlapExpressionUtil.getDisplayColumnName(level.getName())),null,ColumnMeta.UNKNOWN_TYPE);
        meta.setDataType(DataType.STRING_TYPE);
        metaList.add(meta);
        query.addBinding(new Binding(meta.getName(),new ScriptExpression(level.getDisplayColumnName())));
      }
      String levelName=createLevelName(dimName,level.getName());
      query.addBinding(new Binding(levelName,new ScriptExpression(exprString)));
      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(getDefaultStartValue(level.getDateTimeLevelType(),level.getIntervalBase())));
        gd.setInterval(IGroupDefinition.NUMERIC_INTERVAL);
      }
      query.addGroup(gd);
    }
  }
 catch (  DataException e) {
    throw new AdapterException(e.getLocalizedMessage());
  }
}