Program: 58543
Project: 58543
Buggy source:
@Transactional public List<BankStatement> getBankStatements(EbicsPartner ebicsPartner) throws AxelorException, IOException {
  List<BankStatement> bankStatementList=Lists.newArrayList();
  EbicsUser transportEbicsUser=ebicsPartner.getTransportEbicsUser();
  if (ebicsPartner.getBankStatementFileFormatSet() == null || ebicsPartner.getBankStatementFileFormatSet().isEmpty() || transportEbicsUser == null) {
    return bankStatementList;
  }
  LocalDateTime executionDateTime=LocalDateTime.now();
  Date startDate=null;
  Date endDate=null;
  LocalDate bankStatementStartDate=null;
  LocalDate bankStatementToDate=null;
  if (ebicsPartner.getBankStatementGetModeSelect() == EbicsPartnerRepository.GET_MODE_PERIOD) {
    bankStatementStartDate=ebicsPartner.getBankStatementStartDate();
    if (bankStatementStartDate != null) {
      startDate=bankStatementStartDate.toDate();
    }
    bankStatementToDate=ebicsPartner.getBankStatementEndDate();
    if (bankStatementToDate != null) {
      endDate=bankStatementToDate.toDate();
    }
  }
 else   if (ebicsPartner.getBankStatementLastExeDateT() != null) {
    bankStatementStartDate=ebicsPartner.getBankStatementLastExeDateT().toLocalDate();
    bankStatementToDate=executionDateTime.toLocalDate();
  }
  for (  BankStatementFileFormat bankStatementFileFormat : ebicsPartner.getBankStatementFileFormatSet()) {
    try {
      File file=ebicsService.sendFDLRequest(transportEbicsUser,null,startDate,endDate,bankStatementFileFormat.getStatementFileFormatSelect());
      BankStatement bankStatement=bankStatementCreateService.createBankStatement(file,bankStatementStartDate,bankStatementToDate,bankStatementFileFormat,ebicsPartner,executionDateTime);
      bankStatementRepository.save(bankStatement);
      bankStatementList.add(bankStatement);
    }
 catch (    Exception e) {
      TraceBackService.trace(e);
    }
  }
  ebicsPartner.setBankStatementLastExeDateT(executionDateTime);
  Beans.get(EbicsPartnerRepository.class).save(ebicsPartner);
  return bankStatementList;
}

Fixed version (ground truth):
@Transactional public List<BankStatement> getBankStatements(EbicsPartner ebicsPartner) throws AxelorException, IOException {
  List<BankStatement> bankStatementList=Lists.newArrayList();
  EbicsUser transportEbicsUser=ebicsPartner.getTransportEbicsUser();
  if (ebicsPartner.getBankStatementFileFormatSet() == null || ebicsPartner.getBankStatementFileFormatSet().isEmpty() || transportEbicsUser == null) {
    return bankStatementList;
  }
  LocalDateTime executionDateTime=LocalDateTime.now();
  Date startDate=null;
  Date endDate=null;
  LocalDate bankStatementStartDate=null;
  LocalDate bankStatementToDate=null;
  if (ebicsPartner.getBankStatementGetModeSelect() == EbicsPartnerRepository.GET_MODE_PERIOD) {
    bankStatementStartDate=ebicsPartner.getBankStatementStartDate();
    if (bankStatementStartDate != null) {
      startDate=bankStatementStartDate.toDate();
    }
    bankStatementToDate=ebicsPartner.getBankStatementEndDate();
    if (bankStatementToDate != null) {
      endDate=bankStatementToDate.toDate();
    }
  }
 else {
    if (ebicsPartner.getBankStatementLastExeDateT() != null) {
      bankStatementStartDate=ebicsPartner.getBankStatementLastExeDateT().toLocalDate();
    }
    bankStatementToDate=executionDateTime.toLocalDate();
  }
  for (  BankStatementFileFormat bankStatementFileFormat : ebicsPartner.getBankStatementFileFormatSet()) {
    try {
      File file=ebicsService.sendFDLRequest(transportEbicsUser,null,startDate,endDate,bankStatementFileFormat.getStatementFileFormatSelect());
      BankStatement bankStatement=bankStatementCreateService.createBankStatement(file,bankStatementStartDate,bankStatementToDate,bankStatementFileFormat,ebicsPartner,executionDateTime);
      bankStatementRepository.save(bankStatement);
      bankStatementList.add(bankStatement);
    }
 catch (    Exception e) {
      TraceBackService.trace(e);
    }
  }
  ebicsPartner.setBankStatementLastExeDateT(executionDateTime);
  Beans.get(EbicsPartnerRepository.class).save(ebicsPartner);
  return bankStatementList;
}