Program: 75308
Project: 75308
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;
  boolean[] 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) {
    if (argDefs.length != aggrArgs[aggrIndex].length) {
      throw new DataException(ResourceConstants.INVALID_AGGR_PARAMETER,aggrInfo.getName());
    }
    try {
      if (aggrInfo.getArgument().length > argDefs.length && !isFunctionCount(aggrInfo))       throw new DataException("String_Node_Str");
      for (int i=0; i < argDefs.length; i++) {
        if (argDefs[i] || newGroup) {
          IBaseExpression argExpr=aggrInfo.getArgument()[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);
          }
        }
      }
      acc.onRow(aggrArgs[aggrIndex]);
      newGroup=false;
    }
 catch (    DataException e) {
      if (invalidAggrMsg == null)       invalidAggrMsg=new HashMap();
      invalidAggrMsg.put(new Integer(aggrIndex),e);
      return false;
    }
  }
  boolean isRunning=(aggrInfo.getAggregation().getType() == IAggregation.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;
  boolean[] 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) {
    if (!isFunctionCount(aggrInfo)) {
      if (aggrInfo.getArgument() == null || aggrInfo.getArgument().length != argDefs.length)       throw new DataException(ResourceConstants.INVALID_AGGR_PARAMETER,aggrInfo.getName());
    }
    try {
      for (int i=0; i < argDefs.length; i++) {
        if (argDefs[i] || newGroup) {
          IBaseExpression argExpr=aggrInfo.getArgument()[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);
          }
        }
      }
      acc.onRow(aggrArgs[aggrIndex]);
      newGroup=false;
    }
 catch (    DataException e) {
      if (invalidAggrMsg == null)       invalidAggrMsg=new HashMap();
      invalidAggrMsg.put(new Integer(aggrIndex),e);
      return false;
    }
  }
  boolean isRunning=(aggrInfo.getAggregation().getType() == IAggregation.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;
}