Program: 72396
Project: 72396
Buggy source:
/** 
 * @param cubeHandle
 * @param query
 * @param resultMetaList
 * @throws DataException 
 * @throws AdapterException 
 */
private static void prepareMeasure(TabularCubeHandle cubeHandle,QueryDefinition query,List metaList) throws AdapterException {
  try {
    List measureGroups=cubeHandle.getContents(CubeHandle.MEASURE_GROUPS_PROP);
    for (int i=0; i < measureGroups.size(); i++) {
      MeasureGroupHandle mgh=(MeasureGroupHandle)measureGroups.get(i);
      List measures=mgh.getContents(MeasureGroupHandle.MEASURES_PROP);
      for (int j=0; j < measures.size(); j++) {
        MeasureHandle measure=(MeasureHandle)measures.get(j);
        String function=measure.getFunction();
        if (query.getGroups().size() > 0) {
          if (measure.getMeasureExpression() == null || measure.getMeasureExpression().trim().length() == 0)           throw new AdapterException(ResourceConstants.INVALID_MEASURE_EXPRESSION,measure.getName());
          Binding binding=new Binding(measure.getName(),new ScriptExpression(measure.getMeasureExpression()));
          binding.setAggrFunction(DataAdapterUtil.adaptModelAggregationType(function));
          IGroupDefinition group=(IGroupDefinition)query.getGroups().get(query.getGroups().size() - 1);
          binding.addAggregateOn(group.getName());
          query.addBinding(binding);
        }
 else {
          query.addBinding(new Binding(measure.getName(),new ScriptExpression(measure.getMeasureExpression())));
        }
        DataSetIterator.ColumnMeta meta=new DataSetIterator.ColumnMeta(measure.getName(),null,DataSetIterator.ColumnMeta.MEASURE_TYPE);
        meta.setDataType(DataAdapterUtil.adaptModelDataType(measure.getDataType()));
        metaList.add(meta);
      }
    }
  }
 catch (  DataException e) {
    throw new AdapterException(e.getLocalizedMessage());
  }
}

Fixed version (ground truth):
/** 
 * @param cubeHandle
 * @param query
 * @param resultMetaList
 * @throws DataException 
 * @throws AdapterException 
 */
private static void prepareMeasure(TabularCubeHandle cubeHandle,QueryDefinition query,List metaList) throws AdapterException {
  try {
    List measureGroups=cubeHandle.getContents(CubeHandle.MEASURE_GROUPS_PROP);
    for (int i=0; i < measureGroups.size(); i++) {
      MeasureGroupHandle mgh=(MeasureGroupHandle)measureGroups.get(i);
      List measures=mgh.getContents(MeasureGroupHandle.MEASURES_PROP);
      for (int j=0; j < measures.size(); j++) {
        MeasureHandle measure=(MeasureHandle)measures.get(j);
        String function=measure.getFunction();
        String exprText=measure.getMeasureExpression();
        IScriptExpression expr=exprText != null ? new ScriptExpression(exprText) : null;
        if (query.getGroups().size() > 0) {
          Binding binding=new Binding(measure.getName(),expr);
          binding.setAggrFunction(DataAdapterUtil.adaptModelAggregationType(function));
          IGroupDefinition group=(IGroupDefinition)query.getGroups().get(query.getGroups().size() - 1);
          binding.addAggregateOn(group.getName());
          query.addBinding(binding);
        }
 else {
          query.addBinding(new Binding(measure.getName(),expr));
        }
        DataSetIterator.ColumnMeta meta=new DataSetIterator.ColumnMeta(measure.getName(),null,DataSetIterator.ColumnMeta.MEASURE_TYPE);
        meta.setDataType(DataAdapterUtil.adaptModelDataType(measure.getDataType()));
        metaList.add(meta);
      }
    }
  }
 catch (  DataException e) {
    throw new AdapterException(e.getLocalizedMessage());
  }
}