Program: 74776
Project: 74776
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 (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 (binding.getAggrFunction() != null) {
              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());
              if (getAxisQualifierLevel(next,cubeDefn.getEdge(getAxisQualifierEdgeType(dimLevel,cubeDefn))) != 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);
      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 (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 (binding.getAggrFunction() != null) {
              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);
  }
}