Program: 74264
Project: 74264
Buggy source:
public List getReferableBindings(String targetLevel,ICubeQueryDefinition cubeDefn,boolean isSort) throws AdapterException {
  try {
    List bindings=cubeDefn.getBindings();
    if (bindings == null)     return new ArrayList();
    DimLevel target=OlapExpressionUtil.getTargetDimLevel(targetLevel);
    List result=new ArrayList();
    for (int i=0; i < bindings.size(); i++) {
      IBinding binding=(IBinding)bindings.get(i);
      Set refDimLevel=OlapExpressionCompiler.getReferencedDimLevel(binding.getExpression(),bindings,isSort);
      if (refDimLevel.size() > 1)       continue;
      if (!refDimLevel.contains(target)) {
        List aggrOns=binding.getAggregatOns();
        if (aggrOns.size() == 0) {
          if (isGrandTotal(binding) && isSort)           continue;
          if (this.getReferencedMeasureName(binding.getExpression()) != null) {
            if (this.isLeafLevel(cubeDefn,target) && binding.getAggrFunction() == null) {
              result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.MEASURE_TYPE));
              continue;
            }
 else             if (isGrandTotal(binding)) {
              result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.GRAND_TOTAL_TYPE));
              continue;
            }
          }
        }
        for (int j=0; j < aggrOns.size(); j++) {
          DimLevel dimLevel=OlapExpressionUtil.getTargetDimLevel(aggrOns.get(j).toString());
          if (dimLevel.equals(target)) {
            if (j == aggrOns.size() - 1) {
              if (fromSameEdge(aggrOns,cubeDefn))               result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.GRAND_TOTAL_TYPE));
 else               result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.SUB_TOTAL_TYPE));
            }
 else {
              DimLevel next=OlapExpressionUtil.getTargetDimLevel(aggrOns.get(j + 1).toString());
              int candidateEdge=getAxisQualifierEdgeType(dimLevel,cubeDefn);
              if (candidateEdge != -1) {
                if (getAxisQualifierLevel(next,cubeDefn.getEdge(candidateEdge)) != null)                 result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.SUB_TOTAL_TYPE));
              }
            }
            break;
          }
        }
        continue;
      }
      result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.DIMENSION_TYPE));
    }
    return result;
  }
 catch (  DataException e) {
    throw new AdapterException(e.getLocalizedMessage(),e);
  }
}

Fixed version (ground truth):
/** 
 * @param cubeDefn
 * @return
 * @throws DataException
 */
private List getReferableBindings(ICubeQueryDefinition cubeDefn) throws DataException {
  List result=new ArrayList();
  List bindings=cubeDefn.getBindings();
  for (int i=0; i < bindings.size(); i++) {
    IBinding binding=(IBinding)bindings.get(i);
    if (getReferencedMeasureName(binding.getExpression()) != null) {
      List aggrOns=binding.getAggregatOns();
      if (aggrOns.size() == 0 && !isGrandTotal(binding)) {
        result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.MEASURE_TYPE));
      }
 else {
        if (fromSameEdge(aggrOns,cubeDefn)) {
          result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.GRAND_TOTAL_TYPE));
        }
 else         result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.SUB_TOTAL_TYPE));
      }
    }
  }
  return result;
}