Program: 4195
Project: 4195
Buggy source:
private ExecutionTimeResult potentialPreviousClosestMatch(ZonedDateTime date) throws NoSuchValueException {
  List<Integer> year=yearsValueGenerator.generateCandidates(date.getYear(),date.getYear());
  TimeNode days=null;
  try {
    days=generateDays(cronDefinition,date);
  }
 catch (  NoDaysForMonthException e) {
    return new ExecutionTimeResult(date.minusMonths(1),false);
  }
  int highestMonth=months.getValues().get(months.getValues().size() - 1);
  int highestDay=days.getValues().get(days.getValues().size() - 1);
  int highestHour=hours.getValues().get(hours.getValues().size() - 1);
  int highestMinute=minutes.getValues().get(minutes.getValues().size() - 1);
  int highestSecond=seconds.getValues().get(seconds.getValues().size() - 1);
  NearestValue nearestValue;
  ZonedDateTime newDate;
  if (year.isEmpty()) {
    int previousYear=yearsValueGenerator.generatePreviousValue(date.getYear());
    if (highestDay > 28) {
      int highestDayOfMonth=LocalDate.of(previousYear,highestMonth,1).lengthOfMonth();
      if (highestDay > highestDayOfMonth) {
        nearestValue=days.getPreviousValue(highestDay,1);
        if (nearestValue.getShifts() > 0) {
          newDate=ZonedDateTime.of(LocalDateTime.of(previousYear,highestMonth,1,23,59,59),ZoneId.systemDefault()).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth());
          return new ExecutionTimeResult(newDate,false);
        }
 else {
          highestDay=nearestValue.getValue();
        }
      }
    }
    return initDateTime(previousYear,highestMonth,highestDay,highestHour,highestMinute,highestSecond,date.getZone());
  }
  if (!months.getValues().contains(date.getMonthValue())) {
    nearestValue=months.getPreviousValue(date.getMonthValue(),0);
    int previousMonths=nearestValue.getValue();
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),12,31,23,59,59),date.getZone()).minusYears(nearestValue.getShifts());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),previousMonths,highestDay,highestHour,highestMinute,highestSecond,date.getZone());
  }
  if (!days.getValues().contains(date.getDayOfMonth())) {
    nearestValue=days.getPreviousValue(date.getDayOfMonth(),0);
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),date.getMonthValue(),1,23,59,59),date.getZone()).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),date.getMonthValue(),nearestValue.getValue(),highestHour,highestMinute,highestSecond,date.getZone());
  }
  if (!hours.getValues().contains(date.getHour())) {
    nearestValue=hours.getPreviousValue(date.getHour(),0);
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),23,59,59),date.getZone()).minusDays(nearestValue.getShifts());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),nearestValue.getValue(),highestMinute,highestSecond,date.getZone());
  }
  if (!minutes.getValues().contains(date.getMinute())) {
    nearestValue=minutes.getPreviousValue(date.getMinute(),0);
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),date.getHour(),59,59),date.getZone()).minusHours(nearestValue.getShifts());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),date.getHour(),nearestValue.getValue(),highestSecond,date.getZone());
  }
  if (!seconds.getValues().contains(date.getSecond())) {
    nearestValue=seconds.getPreviousValue(date.getSecond(),0);
    int previousSeconds=nearestValue.getValue();
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),date.getHour(),date.getMinute(),59),date.getZone()).minusMinutes(nearestValue.getShifts());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),date.getHour(),date.getMinute(),previousSeconds,date.getZone());
  }
  return new ExecutionTimeResult(date,true);
}

Fixed version (ground truth):
private ExecutionTimeResult potentialPreviousClosestMatch(ZonedDateTime date) throws NoSuchValueException {
  List<Integer> year=yearsValueGenerator.generateCandidates(date.getYear(),date.getYear());
  TimeNode days=null;
  try {
    days=generateDays(cronDefinition,date);
  }
 catch (  NoDaysForMonthException e) {
    return new ExecutionTimeResult(toEndOfPreviousMonth(date),false);
  }
  int highestMonth=months.getValues().get(months.getValues().size() - 1);
  int highestDay=days.getValues().get(days.getValues().size() - 1);
  int highestHour=hours.getValues().get(hours.getValues().size() - 1);
  int highestMinute=minutes.getValues().get(minutes.getValues().size() - 1);
  int highestSecond=seconds.getValues().get(seconds.getValues().size() - 1);
  NearestValue nearestValue;
  ZonedDateTime newDate;
  if (year.isEmpty()) {
    int previousYear=yearsValueGenerator.generatePreviousValue(date.getYear());
    if (highestDay > 28) {
      int highestDayOfMonth=LocalDate.of(previousYear,highestMonth,1).lengthOfMonth();
      if (highestDay > highestDayOfMonth) {
        nearestValue=days.getPreviousValue(highestDay,1);
        if (nearestValue.getShifts() > 0) {
          newDate=ZonedDateTime.of(LocalDateTime.of(previousYear,highestMonth,1,23,59,59),ZoneId.systemDefault()).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth());
          return new ExecutionTimeResult(newDate,false);
        }
 else {
          highestDay=nearestValue.getValue();
        }
      }
    }
    return initDateTime(previousYear,highestMonth,highestDay,highestHour,highestMinute,highestSecond,date.getZone());
  }
  if (!months.getValues().contains(date.getMonthValue())) {
    nearestValue=months.getPreviousValue(date.getMonthValue(),0);
    int previousMonths=nearestValue.getValue();
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),12,31,23,59,59),date.getZone()).minusYears(nearestValue.getShifts());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),previousMonths,highestDay,highestHour,highestMinute,highestSecond,date.getZone());
  }
  if (!days.getValues().contains(date.getDayOfMonth())) {
    nearestValue=days.getPreviousValue(date.getDayOfMonth(),0);
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),date.getMonthValue(),1,23,59,59),date.getZone()).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),date.getMonthValue(),nearestValue.getValue(),highestHour,highestMinute,highestSecond,date.getZone());
  }
  if (!hours.getValues().contains(date.getHour())) {
    nearestValue=hours.getPreviousValue(date.getHour(),0);
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),23,59,59),date.getZone()).minusDays(nearestValue.getShifts());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),nearestValue.getValue(),highestMinute,highestSecond,date.getZone());
  }
  if (!minutes.getValues().contains(date.getMinute())) {
    nearestValue=minutes.getPreviousValue(date.getMinute(),0);
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),date.getHour(),59,59),date.getZone()).minusHours(nearestValue.getShifts());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),date.getHour(),nearestValue.getValue(),highestSecond,date.getZone());
  }
  if (!seconds.getValues().contains(date.getSecond())) {
    nearestValue=seconds.getPreviousValue(date.getSecond(),0);
    int previousSeconds=nearestValue.getValue();
    if (nearestValue.getShifts() > 0) {
      newDate=ZonedDateTime.of(LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),date.getHour(),date.getMinute(),59),date.getZone()).minusMinutes(nearestValue.getShifts());
      return new ExecutionTimeResult(newDate,false);
    }
    return initDateTime(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),date.getHour(),date.getMinute(),previousSeconds,date.getZone());
  }
  return new ExecutionTimeResult(date,true);
}