Program: 73999
Project: 73999
Buggy source:
/** 
 * Valid bindings, return a list of invalid binding.
 * @param queryDefn
 * @param suppressException
 * @return
 * @throws DataException
 */
public static List validateBinding(ICubeQueryDefinition queryDefn,boolean suppressException) throws DataException {
  List result=new ArrayList();
  Set validMeasures=new HashSet();
  for (int i=0; i < queryDefn.getMeasures().size(); i++) {
    IMeasureDefinition measure=(IMeasureDefinition)queryDefn.getMeasures().get(i);
    validMeasures.add(measure.getName());
  }
  Set validDimLevels=new HashSet();
  populateLevel(queryDefn,validDimLevels,ICubeQueryDefinition.COLUMN_EDGE);
  populateLevel(queryDefn,validDimLevels,ICubeQueryDefinition.ROW_EDGE);
  for (int i=0; i < queryDefn.getBindings().size(); i++) {
    boolean isValid=true;
    IBinding binding=(IBinding)queryDefn.getBindings().get(i);
    if (binding.getAggrFunction() != null && binding.getExpression() instanceof IScriptExpression) {
      String expr=((IScriptExpression)binding.getExpression()).getText();
      if (expr == null && (AggregationFactory.getInstance().getAggrInfo(binding.getAggrFunction()) != null && !AggregationFactory.getInstance().getAggrInfo(binding.getAggrFunction()).needDataField()))       continue;
    }
    Set levels=OlapExpressionCompiler.getReferencedDimLevel(binding.getExpression(),queryDefn.getBindings());
    if (!validDimLevels.containsAll(levels)) {
      isValid=false;
      if (!suppressException)       throw new DataException(ResourceConstants.INVALID_BINDING_REFER_TO_INEXIST_DIMENSION,binding.getBindingName());
    }
    String measureName=OlapExpressionCompiler.getReferencedScriptObject(binding.getExpression(),ScriptConstants.MEASURE_SCRIPTABLE);
    if (measureName != null && !validMeasures.contains(measureName)) {
      isValid=false;
      if (!suppressException)       throw new DataException(ResourceConstants.INVALID_BINDING_REFER_TO_INEXIST_MEASURE,binding.getBindingName());
    }
    if ((binding.getAggregatOns().size() > 0 && binding.getAggrFunction() == null)) {
      isValid=false;
      if (!suppressException)       throw new DataException(ResourceConstants.INVALID_BINDING_MISSING_AGGR_FUNC,binding.getBindingName());
    }
    if (!isValid)     result.add(binding);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Valid bindings, return a list of invalid binding.
 * @param queryDefn
 * @param suppressException
 * @return
 * @throws DataException
 */
public static List validateBinding(ICubeQueryDefinition queryDefn,boolean suppressException) throws DataException {
  List result=new ArrayList();
  Set validDimLevels=new HashSet();
  populateLevel(queryDefn,validDimLevels,ICubeQueryDefinition.COLUMN_EDGE);
  populateLevel(queryDefn,validDimLevels,ICubeQueryDefinition.ROW_EDGE);
  for (int i=0; i < queryDefn.getBindings().size(); i++) {
    boolean isValid=true;
    IBinding binding=(IBinding)queryDefn.getBindings().get(i);
    if (binding.getAggrFunction() != null && binding.getExpression() instanceof IScriptExpression) {
      String expr=((IScriptExpression)binding.getExpression()).getText();
      if (expr == null && (AggregationFactory.getInstance().getAggrInfo(binding.getAggrFunction()) != null && !AggregationFactory.getInstance().getAggrInfo(binding.getAggrFunction()).needDataField()))       continue;
    }
    Set levels=OlapExpressionCompiler.getReferencedDimLevel(binding.getExpression(),queryDefn.getBindings());
    if (!validDimLevels.containsAll(levels)) {
      isValid=false;
      if (!suppressException)       throw new DataException(ResourceConstants.INVALID_BINDING_REFER_TO_INEXIST_DIMENSION,binding.getBindingName());
    }
    if ((binding.getAggregatOns().size() > 0 && binding.getAggrFunction() == null)) {
      isValid=false;
      if (!suppressException)       throw new DataException(ResourceConstants.INVALID_BINDING_MISSING_AGGR_FUNC,binding.getBindingName());
    }
    if (!isValid)     result.add(binding);
  }
  return result;
}