Program: 50869
Project: 50869
Buggy source:
/** 
 * Creates a RolapResult.
 * @param execution Execution of a statement
 * @param execute Whether to execute the query
 */
RolapResult(final Execution execution,boolean execute){
  super(execution,null);
  this.point=CellKey.Generator.newCellKey(axes.length);
  final AggregationManager aggMgr=execution.getMondrianStatement().getMondrianConnection().getServer().getAggregationManager();
  this.aggregatingReader=aggMgr.getCacheCellReader();
  final int expDeps=MondrianProperties.instance().TestExpDependencies.get();
  if (expDeps > 0) {
    this.evaluator=new RolapDependencyTestingEvaluator(this,expDeps);
  }
 else {
    final RolapEvaluatorRoot root=new RolapResultEvaluatorRoot(this);
    if (statement.getProfileHandler() != null) {
      this.evaluator=new RolapProfilingEvaluator(root);
    }
 else {
      this.evaluator=new RolapEvaluator(root);
    }
  }
  RolapCube cube=(RolapCube)query.getCube();
  this.batchingReader=new FastBatchingCellReader(execution,cube,aggMgr);
  this.cellInfos=(query.axes.length > 4) ? new CellInfoMap(point) : new CellInfoPool(query.axes.length);
  if (!execute) {
    return;
  }
  boolean normalExecution=true;
  try {
    cube.clearCachedAggregations();
    final AxisMemberList axisMembers=new AxisMemberList();
    final List<Member> nonDefaultAllMembers=new ArrayList<Member>();
    List<List<Member>> nonAllMembers=new ArrayList<List<Member>>();
    final List<Member> measureMembers=new ArrayList<Member>();
    loadSpecialMembers(nonDefaultAllMembers,nonAllMembers,measureMembers);
    query.clearEvalCache();
    query.putEvalCache("String_Node_Str",nonDefaultAllMembers);
    final List<List<Member>> emptyNonAllMembers=Collections.emptyList();
    slicerEvaluator=evaluator.push();
    axisMembers.setSlicer(true);
    loadMembers(emptyNonAllMembers,evaluator,query.getSlicerAxis(),query.slicerCalc,axisMembers);
    axisMembers.setSlicer(false);
    final RolapEvaluator savedEvaluator=evaluator.push();
    if (!axisMembers.isEmpty()) {
      for (      Member m : axisMembers) {
        if (m == null) {
          break;
        }
        evaluator.setSlicerContext(m);
        if (m.isMeasure()) {
          measureMembers.clear();
        }
      }
      replaceNonAllMembers(nonAllMembers,axisMembers);
      axisMembers.clearMembers();
    }
    slicerEvaluator=evaluator.push();
    boolean changed=false;
    axisMembers.clearTotalCellCount();
    for (int i=0; i < axes.length; i++) {
      final QueryAxis axis=query.axes[i];
      final Calc calc=query.axisCalcs[i];
      loadMembers(emptyNonAllMembers,evaluator,axis,calc,axisMembers);
    }
    if (!axisMembers.isEmpty()) {
      for (      Member m : axisMembers) {
        if (m.isMeasure()) {
          measureMembers.clear();
        }
      }
      changed=replaceNonAllMembers(nonAllMembers,axisMembers);
      axisMembers.clearMembers();
    }
    if (changed) {
      axisMembers.countOnly(true);
      axisMembers.clearTotalCellCount();
      final int savepoint=evaluator.savepoint();
      try {
        for (int i=0; i < axes.length; i++) {
          final QueryAxis axis=query.axes[i];
          final Calc calc=query.axisCalcs[i];
          loadMembers(nonAllMembers,evaluator,axis,calc,axisMembers);
          evaluator.restore(savepoint);
        }
      }
  finally {
        evaluator.restore(savepoint);
      }
    }
    axisMembers.checkLimit();
    Axis savedSlicerAxis;
    RolapEvaluator slicerEvaluator;
    do {
      TupleIterable tupleIterable=evalExecute(nonAllMembers,nonAllMembers.size() - 1,savedEvaluator,query.getSlicerAxis(),query.slicerCalc);
      TupleList tupleList=TupleCollections.materialize(tupleIterable,true);
      this.slicerAxis=new RolapAxis(tupleList);
      savedSlicerAxis=this.slicerAxis;
      slicerEvaluator=this.evaluator;
      if (tupleList.size() > 1) {
        tupleList=AggregateFunDef.AggregateCalc.optimizeTupleList(slicerEvaluator,tupleList,false);
        evaluator.setSlicerTuples(tupleList);
        final Calc valueCalc=new ValueCalc(new DummyExp(new ScalarType()));
        final List<Member> prevSlicerMembers=new ArrayList<Member>();
        final Calc calc=new GenericCalc(new DummyExp(query.slicerCalc.getType())){
          public Object evaluate(          Evaluator evaluator){
            TupleList list=AbstractAggregateFunDef.processUnrelatedDimensions(((RolapEvaluator)evaluator).getOptimizedSlicerTuples(null),evaluator);
            for (            Member member : prevSlicerMembers) {
              if (evaluator.getContext(member.getHierarchy()) instanceof CompoundSlicerRolapMember) {
                evaluator.setContext(member);
              }
            }
            return AggregateFunDef.AggregateCalc.aggregate(valueCalc,evaluator,list);
          }
          public boolean dependsOn(          Hierarchy hierarchy){
            return true;
          }
        }
;
        if (tupleList.get(0).size() > 1) {
          for (int i=1; i < tupleList.get(0).size(); i++) {
            Member placeholder=setPlaceholderSlicerAxis((RolapMember)tupleList.get(0).get(i),calc,false);
            prevSlicerMembers.add(evaluator.setContext(placeholder));
          }
        }
        Member placeholder=setPlaceholderSlicerAxis((RolapMember)tupleList.get(0).get(0),calc,true);
        evaluator.setContext(placeholder);
      }
    }
 while (phase());
    final int savepoint=evaluator.savepoint();
    do {
      try {
        boolean redo;
        do {
          evaluator.restore(savepoint);
          redo=false;
          for (int i=0; i < axes.length; i++) {
            QueryAxis axis=query.axes[i];
            final Calc calc=query.axisCalcs[i];
            TupleIterable tupleIterable=evalExecute(nonAllMembers,nonAllMembers.size() - 1,evaluator,axis,calc);
            if (!nonAllMembers.isEmpty()) {
              final TupleIterator tupleIterator=tupleIterable.tupleIterator();
              if (tupleIterator.hasNext()) {
                List<Member> tuple0=tupleIterator.next();
                for (                Member m : tuple0) {
                  if (m.isCalculated()) {
                    CalculatedMeasureVisitor visitor=new CalculatedMeasureVisitor();
                    m.getExpression().accept(visitor);
                    Dimension dimension=visitor.dimension;
                    if (removeDimension(dimension,nonAllMembers)) {
                      redo=true;
                    }
                  }
                }
              }
            }
            this.axes[i]=new RolapAxis(TupleCollections.materialize(tupleIterable,false));
          }
        }
 while (redo);
      }
 catch (      CellRequestQuantumExceededException e) {
      }
    }
 while (phase());
    evaluator.restore(savepoint);
    final Locus locus=new Locus(execution,null,"String_Node_Str");
    Locus.push(locus);
    try {
      executeBody(slicerEvaluator,query,new int[axes.length]);
    }
  finally {
      Locus.pop(locus);
    }
    if (this.cellInfos.size() > 10000) {
      this.cellInfos.trimToSize();
    }
    this.slicerAxis=savedSlicerAxis;
  }
 catch (  ResultLimitExceededException ex) {
    normalExecution=false;
    evaluator=null;
    slicerEvaluator=null;
    cellInfos=null;
    batchingReader=null;
    for (int i=0; i < axes.length; i++) {
      axes[i]=null;
    }
    slicerAxis=null;
    query.clearEvalCache();
    throw ex;
  }
 finally {
    if (normalExecution) {
      evaluator.clearExpResultCache(true);
    }
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("String_Node_Str" + Util.printMemory());
    }
  }
}

Fixed version (ground truth):
/** 
 * Creates a RolapResult.
 * @param execution Execution of a statement
 * @param execute Whether to execute the query
 */
RolapResult(final Execution execution,boolean execute){
  super(execution,null);
  this.point=CellKey.Generator.newCellKey(axes.length);
  final AggregationManager aggMgr=execution.getMondrianStatement().getMondrianConnection().getServer().getAggregationManager();
  this.aggregatingReader=aggMgr.getCacheCellReader();
  final int expDeps=MondrianProperties.instance().TestExpDependencies.get();
  if (expDeps > 0) {
    this.evaluator=new RolapDependencyTestingEvaluator(this,expDeps);
  }
 else {
    final RolapEvaluatorRoot root=new RolapResultEvaluatorRoot(this);
    if (statement.getProfileHandler() != null) {
      this.evaluator=new RolapProfilingEvaluator(root);
    }
 else {
      this.evaluator=new RolapEvaluator(root);
    }
  }
  RolapCube cube=(RolapCube)query.getCube();
  this.batchingReader=new FastBatchingCellReader(execution,cube,aggMgr);
  this.cellInfos=(query.axes.length > 4) ? new CellInfoMap(point) : new CellInfoPool(query.axes.length);
  if (!execute) {
    return;
  }
  boolean normalExecution=true;
  try {
    cube.clearCachedAggregations();
    final AxisMemberList axisMembers=new AxisMemberList();
    final List<Member> nonDefaultAllMembers=new ArrayList<Member>();
    List<List<Member>> nonAllMembers=new ArrayList<List<Member>>();
    final List<Member> measureMembers=new ArrayList<Member>();
    loadSpecialMembers(nonDefaultAllMembers,nonAllMembers,measureMembers);
    query.clearEvalCache();
    query.putEvalCache("String_Node_Str",nonDefaultAllMembers);
    final List<List<Member>> emptyNonAllMembers=Collections.emptyList();
    slicerEvaluator=evaluator.push();
    axisMembers.setSlicer(true);
    loadMembers(emptyNonAllMembers,evaluator,query.getSlicerAxis(),query.slicerCalc,axisMembers);
    axisMembers.setSlicer(false);
    final RolapEvaluator savedEvaluator=evaluator.push();
    if (!axisMembers.isEmpty()) {
      for (      Member m : axisMembers) {
        if (m == null) {
          break;
        }
        evaluator.setSlicerContext(m);
        if (m.isMeasure()) {
          measureMembers.clear();
        }
      }
      replaceNonAllMembers(nonAllMembers,axisMembers);
      axisMembers.clearMembers();
    }
    slicerEvaluator=evaluator.push();
    Axis savedSlicerAxis;
    RolapEvaluator internalSlicerEvaluator;
    do {
      TupleIterable tupleIterable=evalExecute(nonAllMembers,nonAllMembers.size() - 1,savedEvaluator,query.getSlicerAxis(),query.slicerCalc);
      TupleList tupleList=TupleCollections.materialize(tupleIterable,true);
      this.slicerAxis=new RolapAxis(tupleList);
      savedSlicerAxis=this.slicerAxis;
      internalSlicerEvaluator=this.evaluator;
      if (tupleList.size() > 1) {
        tupleList=removeUnaryMembersFromTupleList(tupleList,evaluator);
        tupleList=AggregateFunDef.AggregateCalc.optimizeTupleList(evaluator,tupleList,false);
        evaluator.setSlicerTuples(tupleList);
        final Calc valueCalc=new ValueCalc(new DummyExp(new ScalarType()));
        final List<Member> prevSlicerMembers=new ArrayList<Member>();
        final Calc calcCached=new GenericCalc(new DummyExp(query.slicerCalc.getType())){
          public Object evaluate(          Evaluator evaluator){
            TupleList list=AbstractAggregateFunDef.processUnrelatedDimensions(((RolapEvaluator)evaluator).getOptimizedSlicerTuples(null),evaluator);
            for (            Member member : prevSlicerMembers) {
              if (evaluator.getContext(member.getHierarchy()) instanceof CompoundSlicerRolapMember) {
                evaluator.setContext(member);
              }
            }
            return AggregateFunDef.AggregateCalc.aggregate(valueCalc,evaluator,list);
          }
          public boolean dependsOn(          Hierarchy hierarchy){
            return true;
          }
        }
;
        final ExpCacheDescriptor cacheDescriptor=new ExpCacheDescriptor(query.getSlicerAxis().getSet(),calcCached,evaluator);
        final Calc calc=new CacheCalc(query.getSlicerAxis().getSet(),cacheDescriptor);
        if (tupleList.get(0).size() > 1) {
          for (int i=1; i < tupleList.get(0).size(); i++) {
            Member placeholder=setPlaceholderSlicerAxis((RolapMember)tupleList.get(0).get(i),calc,false);
            prevSlicerMembers.add(evaluator.setContext(placeholder));
          }
        }
        Member placeholder=setPlaceholderSlicerAxis((RolapMember)tupleList.get(0).get(0),calc,true);
        evaluator.setContext(placeholder);
      }
    }
 while (phase());
    slicerEvaluator=evaluator.push();
    boolean changed=false;
    axisMembers.clearTotalCellCount();
    for (int i=0; i < axes.length; i++) {
      final QueryAxis axis=query.axes[i];
      final Calc calc=query.axisCalcs[i];
      loadMembers(emptyNonAllMembers,evaluator,axis,calc,axisMembers);
    }
    if (!axisMembers.isEmpty()) {
      for (      Member m : axisMembers) {
        if (m.isMeasure()) {
          measureMembers.clear();
        }
      }
      changed=replaceNonAllMembers(nonAllMembers,axisMembers);
      axisMembers.clearMembers();
    }
    if (changed) {
      axisMembers.countOnly(true);
      axisMembers.clearTotalCellCount();
      final int savepoint=evaluator.savepoint();
      try {
        for (int i=0; i < axes.length; i++) {
          final QueryAxis axis=query.axes[i];
          final Calc calc=query.axisCalcs[i];
          loadMembers(nonAllMembers,evaluator,axis,calc,axisMembers);
          evaluator.restore(savepoint);
        }
      }
  finally {
        evaluator.restore(savepoint);
      }
    }
    axisMembers.checkLimit();
    final int savepoint=evaluator.savepoint();
    do {
      try {
        boolean redo;
        do {
          evaluator.restore(savepoint);
          redo=false;
          for (int i=0; i < axes.length; i++) {
            QueryAxis axis=query.axes[i];
            final Calc calc=query.axisCalcs[i];
            TupleIterable tupleIterable=evalExecute(nonAllMembers,nonAllMembers.size() - 1,evaluator,axis,calc);
            if (!nonAllMembers.isEmpty()) {
              final TupleIterator tupleIterator=tupleIterable.tupleIterator();
              if (tupleIterator.hasNext()) {
                List<Member> tuple0=tupleIterator.next();
                for (                Member m : tuple0) {
                  if (m.isCalculated()) {
                    CalculatedMeasureVisitor visitor=new CalculatedMeasureVisitor();
                    m.getExpression().accept(visitor);
                    Dimension dimension=visitor.dimension;
                    if (removeDimension(dimension,nonAllMembers)) {
                      redo=true;
                    }
                  }
                }
              }
            }
            this.axes[i]=new RolapAxis(TupleCollections.materialize(tupleIterable,false));
          }
        }
 while (redo);
      }
 catch (      CellRequestQuantumExceededException e) {
      }
    }
 while (phase());
    evaluator.restore(savepoint);
    final Locus locus=new Locus(execution,null,"String_Node_Str");
    Locus.push(locus);
    try {
      executeBody(internalSlicerEvaluator,query,new int[axes.length]);
    }
  finally {
      Locus.pop(locus);
    }
    if (this.cellInfos.size() > 10000) {
      this.cellInfos.trimToSize();
    }
    this.slicerAxis=savedSlicerAxis;
  }
 catch (  ResultLimitExceededException ex) {
    normalExecution=false;
    evaluator=null;
    slicerEvaluator=null;
    cellInfos=null;
    batchingReader=null;
    for (int i=0; i < axes.length; i++) {
      axes[i]=null;
    }
    slicerAxis=null;
    query.clearEvalCache();
    throw ex;
  }
 finally {
    if (normalExecution) {
      evaluator.clearExpResultCache(true);
    }
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("String_Node_Str" + Util.printMemory());
    }
  }
}