Program: 72847
Project: 72847
Buggy source:
/** 
 * Calculate the value by row
 * @param aggrIndex
 * @param startingGroupLevel
 * @param endingGroupLevel
 * @param context
 * @param scope
 * @throws DataException
 */
private boolean onRow(int aggrIndex,int startingGroupLevel,int endingGroupLevel,boolean populateValue) throws DataException {
  IAggrInfo aggrInfo=getAggrInfo(aggrIndex);
  Accumulator acc=null;
  boolean newGroup=false;
  IParameterDefn[] argDefs=aggrInfo.getAggregation().getParameterDefn();
  if (startingGroupLevel <= aggrInfo.getGroupLevel()) {
    acc=accumulatorManagers[aggrIndex].next();
    acc.start();
    newGroup=true;
  }
 else {
    acc=accumulatorManagers[aggrIndex].getCurrentAccumulator();
  }
  boolean accepted=true;
  if (aggrInfo.getFilter() != null) {
    try {
      Object filterResult=ExprEvaluateUtil.evaluateValue(aggrInfo.getFilter(),this.populator.getCache().getCurrentIndex(),this.populator.getCache().getCurrentResult(),this.populator.getQuery().getExprProcessor().getScope());
      if (filterResult == null)       accepted=true;
 else       accepted=DataTypeUtil.toBoolean(filterResult).booleanValue();
    }
 catch (    BirtException e) {
      if (invalidAggrMsg == null)       invalidAggrMsg=new HashMap();
      invalidAggrMsg.put(new Integer(aggrIndex),e);
      return false;
    }
  }
  if (aggrInfo.getCalcualteLevel() > 0) {
    if (startingGroupLevel > aggrInfo.getCalcualteLevel())     accepted=false;
  }
  if (accepted) {
    final IBaseExpression[] arguments=aggrInfo.getArgument();
    if (!isFunctionCount(aggrInfo) && arguments == null) {
      DataException e=new DataException(ResourceConstants.INVALID_AGGR_PARAMETER,aggrInfo.getName());
      wrapException(aggrIndex,e);
      return false;
    }
    try {
      for (int i=0; i < argDefs.length; i++) {
        if (!argDefs[i].isOptional() || newGroup) {
          if (i >= arguments.length) {
            throw new DataException(ResourceConstants.AGGREGATION_ARGUMENT_ERROR,new Object[]{argDefs[i].getName(),aggrInfo.getName()});
          }
 else {
            IBaseExpression argExpr=arguments[i];
            checkExpression(aggrInfo,argExpr);
            try {
              aggrArgs[aggrIndex][i]=ExprEvaluateUtil.evaluateValue(argExpr,this.populator.getCache().getCurrentIndex(),this.populator.getCache().getCurrentResult(),this.populator.getQuery().getExprProcessor().getScope());
            }
 catch (            BirtException e) {
              throw DataException.wrap(e);
            }
          }
        }
      }
      if (argDefs.length != aggrInfo.getArgument().length) {
        DataException e=new DataException(ResourceConstants.INVALID_AGGR_PARAMETER,aggrInfo.getName());
        wrapException(aggrIndex,e);
        return false;
      }
      acc.onRow(aggrArgs[aggrIndex]);
      newGroup=false;
    }
 catch (    DataException e) {
      wrapException(aggrIndex,e);
      return false;
    }
  }
  boolean isRunning=(aggrInfo.getAggregation().getType() == IAggrFunction.RUNNING_AGGR);
  if (isRunning && populateValue) {
    Object value=acc.getValue();
    currentRoundAggrValue[aggrIndex].add(value);
  }
  if (endingGroupLevel <= aggrInfo.getGroupLevel()) {
    acc.finish();
    if ((!isRunning) && populateValue) {
      Object value=acc.getValue();
      currentRoundAggrValue[aggrIndex].add(value);
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Calculate the value by row
 * @param aggrIndex
 * @param startingGroupLevel
 * @param endingGroupLevel
 * @param context
 * @param scope
 * @throws DataException
 */
private boolean onRow(int aggrIndex,int startingGroupLevel,int endingGroupLevel,boolean populateValue) throws DataException {
  IAggrInfo aggrInfo=getAggrInfo(aggrIndex);
  Accumulator acc=null;
  boolean newGroup=false;
  IParameterDefn[] argDefs=aggrInfo.getAggregation().getParameterDefn();
  if (startingGroupLevel <= aggrInfo.getGroupLevel()) {
    acc=accumulatorManagers[aggrIndex].next();
    acc.start();
    newGroup=true;
  }
 else {
    acc=accumulatorManagers[aggrIndex].getCurrentAccumulator();
  }
  boolean accepted=true;
  if (aggrInfo.getFilter() != null) {
    try {
      Object filterResult=ExprEvaluateUtil.evaluateValue(aggrInfo.getFilter(),this.populator.getCache().getCurrentIndex(),this.populator.getCache().getCurrentResult(),this.populator.getQuery().getExprProcessor().getScope());
      if (filterResult == null)       accepted=true;
 else       accepted=DataTypeUtil.toBoolean(filterResult).booleanValue();
    }
 catch (    BirtException e) {
      if (invalidAggrMsg == null)       invalidAggrMsg=new HashMap();
      invalidAggrMsg.put(new Integer(aggrIndex),e);
      return false;
    }
  }
  if (aggrInfo.getCalcualteLevel() > 0) {
    if (startingGroupLevel > aggrInfo.getCalcualteLevel())     accepted=false;
  }
  if (accepted) {
    final IBaseExpression[] arguments=aggrInfo.getArgument();
    if (!isFunctionCount(aggrInfo) && arguments == null) {
      DataException e=new DataException(ResourceConstants.INVALID_AGGR_PARAMETER,aggrInfo.getName());
      wrapException(aggrIndex,e);
      return false;
    }
    try {
      int optionalAgrsNum=0;
      for (int i=0; i < argDefs.length; i++) {
        if (argDefs[i].isOptional()) {
          optionalAgrsNum++;
        }
        if (aggrInfo.getArgument() == null || i >= arguments.length + optionalAgrsNum) {
          throw new DataException(ResourceConstants.AGGREGATION_ARGUMENT_ERROR,new Object[]{argDefs[i].getName(),aggrInfo.getName()});
        }
        if (isEmptyScriptExpression(aggrInfo)) {
          aggrArgs[aggrIndex]=null;
        }
 else {
          evaluateArgsValue(aggrIndex,aggrInfo,i);
        }
      }
      if (aggrInfo.getArgument() == null || ((aggrInfo.getArgument().length != argDefs.length) && !(aggrInfo.getArgument().length == (argDefs.length - optionalAgrsNum)))) {
        DataException e=new DataException(ResourceConstants.INVALID_AGGR_PARAMETER,aggrInfo.getName());
        wrapException(aggrIndex,e);
        return false;
      }
      acc.onRow(aggrArgs[aggrIndex]);
      newGroup=false;
    }
 catch (    DataException e) {
      wrapException(aggrIndex,e);
      return false;
    }
  }
  boolean isRunning=(aggrInfo.getAggregation().getType() == IAggrFunction.RUNNING_AGGR);
  if (isRunning && populateValue) {
    Object value=acc.getValue();
    currentRoundAggrValue[aggrIndex].add(value);
  }
  if (endingGroupLevel <= aggrInfo.getGroupLevel()) {
    acc.finish();
    if ((!isRunning) && populateValue) {
      Object value=acc.getValue();
      currentRoundAggrValue[aggrIndex].add(value);
    }
  }
  return true;
}