Program: 72595
Project: 72595
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 (isGrandTotal(binding) && isSort)         continue;
        if (this.getReferencedMeasureName(binding.getExpression()) != null) {
          if (this.isLeafLevel(cubeDefn,target) && this.isMeasureBinding(cubeDefn,binding)) {
            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):
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);
      if (!OlapExpressionUtil.isDirectRerenrence(binding.getExpression(),bindings)) {
        result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.OTHER_TYPE));
        continue;
      }
      Set refDimLevel=OlapExpressionCompiler.getReferencedDimLevel(binding.getExpression(),bindings,isSort);
      if (refDimLevel.size() > 1)       continue;
      if (!refDimLevel.contains(target)) {
        List aggrOns=binding.getAggregatOns();
        if (isGrandTotal(binding) && isSort)         continue;
        if (this.getReferencedMeasureName(binding.getExpression()) != null) {
          if (this.isLeafLevel(cubeDefn,target) && this.isMeasureBinding(cubeDefn,binding)) {
            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);
  }
}