Program: 59048
Project: 59048
Buggy source:
/** 
 * Procédure permettant de cloturer un exercice comptable
 * @param year Un exercice comptable
 * @throws AxelorException 
 */
@Transactional(rollbackOn={AxelorException.class,Exception.class}) public void closeYear(Year year) throws AxelorException {
  year=Year.find(year.getId());
  Status status=Status.findByCode("String_Node_Str");
  for (  Period period : year.getPeriodList()) {
    period.setStatus(status);
  }
  Company company=year.getCompany();
  if (company == null) {
    throw new AxelorException(String.format("String_Node_Str",GeneralServiceAccount.getExceptionAccountingMsg(),year.getName()),IException.CONFIGURATION_ERROR);
  }
  Query q=JPA.em().createQuery("String_Node_Str");
  q.setParameter(1,year.getFromDate());
  q.setParameter(2,year.getToDate());
  q.setParameter(3,year.getCompany());
  @SuppressWarnings("String_Node_Str") List<Partner> partnerList=q.getResultList();
  List<Partner> partnerListAll=Partner.all().fetch();
  LOG.debug("String_Node_Str",partnerListAll.size());
  LOG.debug("String_Node_Str",partnerList.size());
  AccountConfig accountConfig=accountConfigService.getAccountConfig(company);
  Account customerAccount=accountConfigService.getCustomerAccount(accountConfig);
  Account doubtfulCustomerAccount=accountConfigService.getDoubtfulCustomerAccount(accountConfig);
  for (  Partner partner : partnerList) {
    partner=Partner.find(partner.getId());
    LOG.debug("String_Node_Str",partner.getName());
    boolean find=false;
    for (    ReportedBalance reportedBalance : partner.getReportedBalanceList()) {
      if (reportedBalance.getCompany().equals(company)) {
        LOG.debug("String_Node_Str");
        ReportedBalanceLine reportedBalanceLine=this.createReportedBalanceLine(reportedBalance,this.computeReportedBalance(year.getFromDate(),year.getToDate(),partner,customerAccount,doubtfulCustomerAccount),year);
        LOG.debug("String_Node_Str",reportedBalanceLine);
        reportedBalance.getReportedBalanceLineList().add(reportedBalanceLine);
        reportedBalance.save();
        find=true;
      }
    }
    if (!find) {
      LOG.debug("String_Node_Str");
      ReportedBalance reportedBalance=this.createReportedBalance(company,partner);
      ReportedBalanceLine reportedBalanceLine=this.createReportedBalanceLine(reportedBalance,this.computeReportedBalance(year.getFromDate(),year.getToDate(),partner,customerAccount,doubtfulCustomerAccount),year);
      LOG.debug("String_Node_Str",reportedBalanceLine);
      reportedBalance.getReportedBalanceLineList().add(reportedBalanceLine);
      reportedBalance.save();
    }
    partner.save();
  }
  year.setStatus(status);
  year.save();
}

Fixed version (ground truth):
/** 
 * Procédure permettant de cloturer un exercice comptable
 * @param year Un exercice comptable
 * @throws AxelorException 
 */
@Transactional(rollbackOn={AxelorException.class,Exception.class}) public void closeYear(Year year) throws AxelorException {
  year=Year.find(year.getId());
  Status status=Status.findByCode("String_Node_Str");
  for (  Period period : year.getPeriodList()) {
    period.setStatus(status);
  }
  Company company=year.getCompany();
  if (company == null) {
    throw new AxelorException(String.format("String_Node_Str",GeneralServiceAccount.getExceptionAccountingMsg(),year.getName()),IException.CONFIGURATION_ERROR);
  }
  Query q=JPA.em().createQuery("String_Node_Str");
  q.setParameter(1,year.getFromDate());
  q.setParameter(2,year.getToDate());
  q.setParameter(3,year.getCompany());
  @SuppressWarnings("String_Node_Str") List<Partner> partnerList=q.getResultList();
  List<? extends Partner> partnerListAll=Partner.all().fetch();
  LOG.debug("String_Node_Str",partnerListAll.size());
  LOG.debug("String_Node_Str",partnerList.size());
  AccountConfig accountConfig=accountConfigService.getAccountConfig(company);
  Account customerAccount=accountConfigService.getCustomerAccount(accountConfig);
  Account doubtfulCustomerAccount=accountConfigService.getDoubtfulCustomerAccount(accountConfig);
  for (  Partner partner : partnerList) {
    partner=Partner.find(partner.getId());
    LOG.debug("String_Node_Str",partner.getName());
    boolean find=false;
    for (    ReportedBalance reportedBalance : partner.getReportedBalanceList()) {
      if (reportedBalance.getCompany().equals(company)) {
        LOG.debug("String_Node_Str");
        ReportedBalanceLine reportedBalanceLine=this.createReportedBalanceLine(reportedBalance,this.computeReportedBalance(year.getFromDate(),year.getToDate(),partner,customerAccount,doubtfulCustomerAccount),year);
        LOG.debug("String_Node_Str",reportedBalanceLine);
        reportedBalance.getReportedBalanceLineList().add(reportedBalanceLine);
        reportedBalance.save();
        find=true;
      }
    }
    if (!find) {
      LOG.debug("String_Node_Str");
      ReportedBalance reportedBalance=this.createReportedBalance(company,partner);
      ReportedBalanceLine reportedBalanceLine=this.createReportedBalanceLine(reportedBalance,this.computeReportedBalance(year.getFromDate(),year.getToDate(),partner,customerAccount,doubtfulCustomerAccount),year);
      LOG.debug("String_Node_Str",reportedBalanceLine);
      reportedBalance.getReportedBalanceLineList().add(reportedBalanceLine);
      reportedBalance.save();
    }
    partner.save();
  }
  year.setStatus(status);
  year.save();
}