Program: 65771
Project: 65771
Buggy source:
/** 
 * @param periodHandle
 * @return
 * @throws BirtException 
 * @throws DataException 
 */
private ITimePeriod populateRelativeTimePeriod(ComputedColumnHandle periodHandle) throws DataException, BirtException {
  String calculateType=periodHandle.getCalculationType();
  TimePeriod relativeTimePeriod=null;
  if (IBuildInBaseTimeFunction.WEEK_TO_DATE_LAST_YEAR.equals(calculateType) || IBuildInBaseTimeFunction.MONTH_TO_DATE_LAST_YEAR.equals(calculateType) || IBuildInBaseTimeFunction.QUARTER_TO_DATE_LAST_YEAR.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n),TimePeriodType.YEAR);
  }
 else   if (IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n),TimePeriodType.WEEK);
  }
 else   if (IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE.equals(calculateType) || IBuildInBaseTimeFunction.PREVIOUS_MONTH.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n),TimePeriodType.MONTH);
  }
 else   if (IBuildInBaseTimeFunction.PREVIOUS_QUARTER_TO_DATE.equals(calculateType) || IBuildInBaseTimeFunction.PREVIOUS_QUARTER.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n),TimePeriodType.QUARTER);
  }
 else   if (IBuildInBaseTimeFunction.PREVIOUS_YEAR_TO_DATE.equals(calculateType) || IBuildInBaseTimeFunction.PREVIOUS_YEAR.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n),TimePeriodType.YEAR);
  }
 else   if (IBuildInBaseTimeFunction.CURRENT_PERIOD_FROM_N_PERIOD_AGO.equals(calculateType) || IBuildInBaseTimeFunction.PERIOD_TO_DATE_FROM_N_PERIOD_AGO.equals(calculateType) || IBuildInBaseTimeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String period2=null, n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.PERIOD_2.equals(argument.getName())) {
        period2=argument.getValue().getStringExpression();
      }
      if (IArgumentInfo.N_PERIOD2.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n),DataAdapterUtil.toTimePeriodType(period2));
  }
  return relativeTimePeriod;
}

Fixed version (ground truth):
/** 
 * @param periodHandle
 * @return
 * @throws BirtException 
 * @throws DataException 
 */
private ITimePeriod populateRelativeTimePeriod(ComputedColumnHandle periodHandle) throws DataException, BirtException {
  String calculateType=periodHandle.getCalculationType();
  TimePeriod relativeTimePeriod=null;
  Object expression=null;
  if (IBuildInBaseTimeFunction.WEEK_TO_DATE_LAST_YEAR.equals(calculateType) || IBuildInBaseTimeFunction.MONTH_TO_DATE_LAST_YEAR.equals(calculateType) || IBuildInBaseTimeFunction.QUARTER_TO_DATE_LAST_YEAR.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        expression=argument.getValue().getValue();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n,expression),TimePeriodType.YEAR);
  }
 else   if (IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        expression=argument.getValue().getValue();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n,expression),TimePeriodType.WEEK);
  }
 else   if (IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE.equals(calculateType) || IBuildInBaseTimeFunction.PREVIOUS_MONTH.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        expression=argument.getValue().getValue();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n,expression),TimePeriodType.MONTH);
  }
 else   if (IBuildInBaseTimeFunction.PREVIOUS_QUARTER_TO_DATE.equals(calculateType) || IBuildInBaseTimeFunction.PREVIOUS_QUARTER.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        expression=argument.getValue().getValue();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n,expression),TimePeriodType.QUARTER);
  }
 else   if (IBuildInBaseTimeFunction.PREVIOUS_YEAR_TO_DATE.equals(calculateType) || IBuildInBaseTimeFunction.PREVIOUS_YEAR.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.N_PERIOD1.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        expression=argument.getValue().getValue();
        break;
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n,expression),TimePeriodType.YEAR);
  }
 else   if (IBuildInBaseTimeFunction.CURRENT_PERIOD_FROM_N_PERIOD_AGO.equals(calculateType) || IBuildInBaseTimeFunction.PERIOD_TO_DATE_FROM_N_PERIOD_AGO.equals(calculateType) || IBuildInBaseTimeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO.equals(calculateType)) {
    Iterator iter=periodHandle.calculationArgumentsIterator();
    String period2=null, n=null;
    while (iter.hasNext()) {
      CalculationArgumentHandle argument=(CalculationArgumentHandle)iter.next();
      if (IArgumentInfo.PERIOD_2.equals(argument.getName())) {
        period2=argument.getValue().getStringExpression();
      }
      if (IArgumentInfo.N_PERIOD2.equals(argument.getName())) {
        n=argument.getValue().getStringExpression();
        expression=argument.getValue().getValue();
      }
    }
    relativeTimePeriod=new TimePeriod(0 - evaluatePeriodsN(n,expression),DataAdapterUtil.toTimePeriodType(period2));
  }
  return relativeTimePeriod;
}