Program: 58768
Project: 58768
Buggy source:
public BigDecimal computeDuration(LeaveRequest leave) throws AxelorException {
  if (leave.getDateFrom() != null && leave.getDateTo() != null) {
    Employee employee=leave.getUser().getEmployee();
    if (employee == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE),leave.getUser().getName()),IException.CONFIGURATION_ERROR);
    }
    WeeklyPlanning weeklyPlanning=employee.getPlanning();
    if (weeklyPlanning == null) {
      HRConfig conf=leave.getCompany().getHrConfig();
      if (conf != null) {
        weeklyPlanning=conf.getWeeklyPlanning();
      }
    }
    if (weeklyPlanning == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING),employee.getName()),IException.CONFIGURATION_ERROR);
    }
    PublicHolidayPlanning publicHolidayPlanning=employee.getPublicHolidayPlanning();
    if (publicHolidayPlanning == null) {
      HRConfig conf=leave.getCompany().getHrConfig();
      if (conf != null) {
        publicHolidayPlanning=conf.getPublicHolidayPlanning();
      }
    }
    if (publicHolidayPlanning == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY),employee.getName()),IException.CONFIGURATION_ERROR);
    }
    BigDecimal duration=BigDecimal.ZERO;
    if (leave.getDateFrom().isEqual(leave.getDateTo())) {
      if (leave.getStartOnSelect() == leave.getEndOnSelect())       return new BigDecimal(0.5);
 else       return new BigDecimal(1);
    }
    duration=duration.add(new BigDecimal(this.computeStartDateWithSelect(leave.getDateFrom(),leave.getStartOnSelect(),weeklyPlanning)));
    LocalDate itDate=new LocalDate(leave.getDateFrom().plusDays(1));
    while (!itDate.isEqual(leave.getDateTo()) && !itDate.isAfter(leave.getDateTo())) {
      duration=duration.add(new BigDecimal(weeklyPlanningService.workingDayValue(weeklyPlanning,itDate)));
      itDate=itDate.plusDays(1);
    }
    if (!leave.getDateFrom().isEqual(leave.getDateTo())) {
      duration=duration.add(new BigDecimal(this.computeEndDateWithSelect(leave.getDateTo(),leave.getEndOnSelect(),weeklyPlanning)));
    }
    duration=duration.subtract(Beans.get(PublicHolidayService.class).computePublicHolidayDays(leave.getDateFrom(),leave.getDateTo(),weeklyPlanning,publicHolidayPlanning));
    return duration;
  }
 else {
    return BigDecimal.ZERO;
  }
}

Fixed version (ground truth):
public BigDecimal computeDuration(LeaveRequest leave) throws AxelorException {
  if (leave.getDateFrom() != null && leave.getDateTo() != null) {
    Employee employee=leave.getUser().getEmployee();
    if (employee == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE),leave.getUser().getName()),IException.CONFIGURATION_ERROR);
    }
    WeeklyPlanning weeklyPlanning=employee.getPlanning();
    if (weeklyPlanning == null) {
      HRConfig conf=leave.getCompany().getHrConfig();
      if (conf != null) {
        weeklyPlanning=conf.getWeeklyPlanning();
      }
    }
    if (weeklyPlanning == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING),employee.getName()),IException.CONFIGURATION_ERROR);
    }
    PublicHolidayPlanning publicHolidayPlanning=employee.getPublicHolidayPlanning();
    if (publicHolidayPlanning == null) {
      HRConfig conf=leave.getCompany().getHrConfig();
      if (conf != null) {
        publicHolidayPlanning=conf.getPublicHolidayPlanning();
      }
    }
    if (publicHolidayPlanning == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY),employee.getName()),IException.CONFIGURATION_ERROR);
    }
    BigDecimal duration=BigDecimal.ZERO;
    if (leave.getDateFrom().isEqual(leave.getDateTo())) {
      if (leave.getStartOnSelect() == leave.getEndOnSelect()) {
        if (leave.getStartOnSelect() == LeaveRequestRepository.SELECT_MORNING) {
          duration=duration.add(new BigDecimal(weeklyPlanningService.workingDayValueWithSelect(weeklyPlanning,leave.getDateFrom(),true,false)));
        }
 else {
          duration=duration.add(new BigDecimal(weeklyPlanningService.workingDayValueWithSelect(weeklyPlanning,leave.getDateFrom(),false,true)));
        }
      }
 else {
        duration=duration.add(new BigDecimal(weeklyPlanningService.workingDayValueWithSelect(weeklyPlanning,leave.getDateFrom(),true,true)));
      }
    }
 else {
      duration=duration.add(new BigDecimal(this.computeStartDateWithSelect(leave.getDateFrom(),leave.getStartOnSelect(),weeklyPlanning)));
      LocalDate itDate=new LocalDate(leave.getDateFrom().plusDays(1));
      while (!itDate.isEqual(leave.getDateTo()) && !itDate.isAfter(leave.getDateTo())) {
        duration=duration.add(new BigDecimal(weeklyPlanningService.workingDayValue(weeklyPlanning,itDate)));
        itDate=itDate.plusDays(1);
      }
      duration=duration.add(new BigDecimal(this.computeEndDateWithSelect(leave.getDateTo(),leave.getEndOnSelect(),weeklyPlanning)));
    }
    duration=duration.subtract(Beans.get(PublicHolidayService.class).computePublicHolidayDays(leave.getDateFrom(),leave.getDateTo(),weeklyPlanning,publicHolidayPlanning));
    if (duration.compareTo(BigDecimal.ZERO) < 0) {
      duration.equals(BigDecimal.ZERO);
    }
    return duration;
  }
 else {
    return BigDecimal.ZERO;
  }
}