Program: 67042
Project: 67042
Buggy source:
public ICubeCursor getCubeCursor() throws DataException {
  if (this.cubeCursor != null)   return this.cubeCursor;
  try {
    if (this.session.getEngineContext().getMode() == DataEngineContext.MODE_PRESENTATION) {
      this.cubeCursor=createCursor(null);
      return this.cubeCursor;
    }
    stopSign.start();
    Set<String> involvedDerivedMeasure=new HashSet<String>();
    Set<String> derivedMeasureNames=OlapExpressionUtil.getDerivedMeasureNames(this.cubeQueryDefinition.getBindings());
    List<IBinding> bindingSet=new ArrayList<IBinding>();
    bindingSet.addAll(this.cubeQueryDefinition.getBindings());
    if (this.cubeQueryDefinition instanceof PreparedCubeQueryDefinition) {
      Set<IBinding> binding4NestedAggr=((PreparedCubeQueryDefinition)this.cubeQueryDefinition).getBindingsForNestAggregation();
      for (      IBinding binding : binding4NestedAggr) {
        derivedMeasureNames.add(binding.getBindingName());
      }
      bindingSet.addAll(binding4NestedAggr);
    }
    List<IFilterDefinition> derivedMeasureFilters=new ArrayList<IFilterDefinition>();
    if (!this.cubeQueryDefinition.getFilters().isEmpty()) {
      for (      IFilterDefinition filter : (List<IFilterDefinition>)this.cubeQueryDefinition.getFilters()) {
        IBaseExpression expr=filter.getExpression();
        Set<String> temp=this.getInvolvedDerivedMeasure(expr,derivedMeasureNames,this.cubeQueryDefinition.getBindings());
        if (temp.size() > 0)         derivedMeasureFilters.add(filter);
        involvedDerivedMeasure.addAll(temp);
      }
    }
    if (!this.cubeQueryDefinition.getSorts().isEmpty()) {
      for (      ISortDefinition sort : (List<ISortDefinition>)this.cubeQueryDefinition.getSorts()) {
        IBaseExpression expr=sort.getExpression();
        involvedDerivedMeasure.addAll(this.getInvolvedDerivedMeasure(expr,derivedMeasureNames,this.cubeQueryDefinition.getBindings()));
      }
    }
    if (involvedDerivedMeasure.isEmpty()) {
      this.cubeCursor=createCursor(null);
    }
 else {
      List<String> candidateBindingOfInteresting=new ArrayList<String>();
      candidateBindingOfInteresting.addAll(involvedDerivedMeasure);
      List<Set<String>> bindingDimLevels=new ArrayList<Set<String>>();
      for (      String bindingName : candidateBindingOfInteresting) {
        Set<IDimLevel> dimLevels=OlapExpressionUtil.getAggregateOnLevel(bindingName,bindingSet);
        Set<String> temp=new HashSet<String>();
        for (        IDimLevel dl : dimLevels) {
          temp.add(OlapExpressionUtil.getAttrReference(dl.getDimensionName(),dl.getLevelName(),dl.getLevelName()));
        }
        bindingDimLevels.add(temp);
      }
      List<IFilterDefinition> filterTemp=new ArrayList<IFilterDefinition>();
      List<ISortDefinition> sortTemp=new ArrayList<ISortDefinition>();
      filterTemp.addAll(this.cubeQueryDefinition.getFilters());
      sortTemp.addAll(this.cubeQueryDefinition.getSorts());
      this.cubeQueryDefinition.getFilters().removeAll(derivedMeasureFilters);
      this.cubeQueryDefinition.getSorts().clear();
      this.cubeCursor=createCursor(null);
      this.cubeQueryDefinition.getFilters().clear();
      this.cubeQueryDefinition.getFilters().addAll(filterTemp);
      this.cubeQueryDefinition.getSorts().addAll(sortTemp);
      BindingValueFetcher fetcher=new BindingValueFetcher(this.cubeCursor,this.cubeQueryDefinition,candidateBindingOfInteresting,bindingDimLevels);
      this.cubeCursor=createCursor(fetcher);
    }
    return this.cubeCursor;
  }
 catch (  OLAPException e) {
    throw new DataException(e.getLocalizedMessage(),e);
  }
catch (  IOException e) {
    throw new DataException(e.getLocalizedMessage(),e);
  }
}

Fixed version (ground truth):
public ICubeCursor getCubeCursor() throws DataException {
  if (this.cubeCursor != null)   return this.cubeCursor;
  try {
    if (this.session.getEngineContext().getMode() == DataEngineContext.MODE_PRESENTATION) {
      this.cubeCursor=createCursor(null);
      return this.cubeCursor;
    }
    stopSign.start();
    Set<String> involvedDerivedMeasure=new HashSet<String>();
    Set<String> derivedMeasureNames=OlapExpressionUtil.getDerivedMeasureNames(this.cubeQueryDefinition.getBindings());
    List<IBinding> bindingSet=new ArrayList<IBinding>();
    bindingSet.addAll(this.cubeQueryDefinition.getBindings());
    if (this.cubeQueryDefinition instanceof PreparedCubeQueryDefinition) {
      Set<IBinding> binding4NestedAggr=((PreparedCubeQueryDefinition)this.cubeQueryDefinition).getBindingsForNestAggregation();
      for (      IBinding binding : binding4NestedAggr) {
        derivedMeasureNames.add(binding.getBindingName());
      }
      bindingSet.addAll(binding4NestedAggr);
    }
    List<IFilterDefinition> derivedMeasureFilters=new ArrayList<IFilterDefinition>();
    if (!this.cubeQueryDefinition.getFilters().isEmpty()) {
      for (      IFilterDefinition filter : (List<IFilterDefinition>)this.cubeQueryDefinition.getFilters()) {
        IBaseExpression expr=filter.getExpression();
        Set<String> temp=this.getInvolvedDerivedMeasure(expr,derivedMeasureNames,this.cubeQueryDefinition.getBindings());
        if (temp.size() > 0)         derivedMeasureFilters.add(filter);
        involvedDerivedMeasure.addAll(temp);
      }
    }
    if (!this.cubeQueryDefinition.getSorts().isEmpty()) {
      for (      ISortDefinition sort : (List<ISortDefinition>)this.cubeQueryDefinition.getSorts()) {
        IBaseExpression expr=sort.getExpression();
        involvedDerivedMeasure.addAll(this.getInvolvedDerivedMeasure(expr,derivedMeasureNames,this.cubeQueryDefinition.getBindings()));
      }
    }
    if (involvedDerivedMeasure.isEmpty()) {
      this.cubeCursor=createCursor(null);
    }
 else {
      List<String> candidateBindingOfInteresting=new ArrayList<String>();
      candidateBindingOfInteresting.addAll(involvedDerivedMeasure);
      List<Set<String>> bindingDimLevels=new ArrayList<Set<String>>();
      Set<IDimLevel> mostDetailedMeasureDimLevel=new HashSet<IDimLevel>();
      for (      String bindingName : candidateBindingOfInteresting) {
        Set<IDimLevel> dimLevels=OlapExpressionUtil.getAggregateOnLevel(bindingName,bindingSet,getMeasureDimLevel());
        Set<String> temp=new HashSet<String>();
        for (        IDimLevel dl : dimLevels) {
          temp.add(OlapExpressionUtil.getAttrReference(dl.getDimensionName(),dl.getLevelName(),dl.getLevelName()));
        }
        bindingDimLevels.add(temp);
      }
      List<IFilterDefinition> filterTemp=new ArrayList<IFilterDefinition>();
      List<ISortDefinition> sortTemp=new ArrayList<ISortDefinition>();
      filterTemp.addAll(this.cubeQueryDefinition.getFilters());
      sortTemp.addAll(this.cubeQueryDefinition.getSorts());
      this.cubeQueryDefinition.getFilters().removeAll(derivedMeasureFilters);
      this.cubeQueryDefinition.getSorts().clear();
      this.cubeCursor=createCursor(null);
      this.cubeQueryDefinition.getFilters().clear();
      this.cubeQueryDefinition.getFilters().addAll(filterTemp);
      this.cubeQueryDefinition.getSorts().addAll(sortTemp);
      BindingValueFetcher fetcher=new BindingValueFetcher(this.cubeCursor,this.cubeQueryDefinition,candidateBindingOfInteresting,bindingDimLevels);
      this.cubeCursor=createCursor(fetcher);
    }
    return this.cubeCursor;
  }
 catch (  OLAPException e) {
    throw new DataException(e.getLocalizedMessage(),e);
  }
catch (  IOException e) {
    throw new DataException(e.getLocalizedMessage(),e);
  }
}