Program: 71201
Project: 71201
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(),this.populator.getSession().getEngineContext().getScriptContext());
      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 (isEmptyAggrArgument(aggrInfo)) {
          aggrArgs[aggrIndex]=null;
        }
 else {
          evaluateArgsValue(aggrIndex,aggrInfo,i,argDefs[i].isOptional());
        }
      }
      if (aggrInfo.getArgument() == null || !isValidArgumentNumber(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;
}

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(),this.populator.getSession().getEngineContext().getScriptContext());
      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 (isEmptyAggrArgument(aggrInfo)) {
          aggrArgs[aggrIndex]=null;
        }
 else {
          evaluateArgsValue(aggrIndex,aggrInfo,i,argDefs[i]);
        }
      }
      if (aggrInfo.getArgument() == null || !isValidArgumentNumber(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;
}