Program: 74830
Project: 74830
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 && this.isLeafLevel(cubeDefn,target)) {
            result.add(binding);
            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)             result.add(binding);
 else {
              DimLevel next=OlapExpressionUtil.getTargetDimLevel(aggrOns.get(j + 1).toString());
              if (getAxisQualifierLevel(next,cubeDefn.getEdge(getAxisQualifierEdgeType(dimLevel,cubeDefn))) == null)               continue;
 else               result.add(binding);
            }
            break;
          }
        }
        continue;
      }
      result.add(binding);
    }
    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 && this.isLeafLevel(cubeDefn,target)) {
            result.add(new BindingMetaInfo(binding.getBindingName(),IBindingMetaInfo.MEASURE_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);
  }
}