Program: 59151
Project: 59151
Buggy source:
/** 
 * Méthode permettant de générer l'ensemble des exports des prélèvements pour Mensu
 * @param paymentScheduleExport Un objet d'export des prélèvements
 * @param company Une société
 * @param paymentMode Un mode de paiement
 * @param statusVal Un status
 * @param journal Un journal
 * @param isMajorAccount Le traitement concerne le prélèvement des échéances de mensu grand compte ?
 * @return 
 * @return
 * @throws AxelorException
 */
public List<PaymentScheduleLine> generateAllExportMensu(List<PaymentScheduleLine> pslList,Company company,PaymentMode paymentMode,Status statusVal,Journal journal){
  Move move=null;
  try {
    move=paymentScheduleExportService.createExportMensuMove(Journal.find(journal.getId()),Company.find(company.getId()),PaymentMode.find(paymentMode.getId()));
  }
 catch (  AxelorException e) {
    TraceBackService.trace(new AxelorException(String.format("String_Node_Str",batch.getId()),e,e.getcategory()),IException.DIRECT_DEBIT,batch.getId());
    incrementAnomaly();
    stop=true;
  }
catch (  Exception e) {
    TraceBackService.trace(new Exception(String.format("String_Node_Str",batch.getId()),e),IException.DIRECT_DEBIT,batch.getId());
    incrementAnomaly();
    LOG.error("String_Node_Str",batch.getId());
    stop=true;
  }
  int ref=1;
  int i=0;
  List<PaymentScheduleLine> pslListToExport=new ArrayList<PaymentScheduleLine>();
  if (!stop) {
    for (    PaymentScheduleLine paymentScheduleLine : pslList) {
      try {
        if (paymentScheduleExportService.isDebitBlocking(paymentScheduleLine)) {
          PaymentScheduleLine paymentScheduleLineToExport=paymentScheduleExportService.generateExportMensu(PaymentScheduleLine.find(paymentScheduleLine.getId()),pslList,Status.find(statusVal.getId()),Company.find(company.getId()),ref,Move.find(move.getId()));
          if (paymentScheduleLineToExport != null) {
            ref++;
            i++;
            pslListToExport.add(paymentScheduleLineToExport);
            updatePaymentScheduleLine(paymentScheduleLineToExport);
            this.totalAmount=this.totalAmount.add(PaymentScheduleLine.find(paymentScheduleLine.getId()).getInTaxAmount());
          }
        }
      }
 catch (      AxelorException e) {
        TraceBackService.trace(new AxelorException(String.format("String_Node_Str",paymentScheduleLine.getName()),e,e.getcategory()),IException.DIRECT_DEBIT,batch.getId());
        incrementAnomaly();
      }
catch (      Exception e) {
        TraceBackService.trace(new Exception(String.format("String_Node_Str",paymentScheduleLine.getName()),e),IException.DIRECT_DEBIT,batch.getId());
        incrementAnomaly();
        LOG.error("String_Node_Str",paymentScheduleLine.getName());
      }
 finally {
        if (i % 10 == 0) {
          JPA.clear();
        }
      }
    }
  }
  try {
    if (ref != 1) {
      Account bankAccount=paymentModeService.getCompanyAccount(PaymentMode.find(paymentMode.getId()),Company.find(company.getId()));
      paymentScheduleExportService.createOppositeExportMensuMoveLine(Move.find(move.getId()),bankAccount,ref);
      paymentScheduleExportService.validateMove(Move.find(move.getId()));
    }
 else {
      paymentScheduleExportService.deleteMove(Move.find(move.getId()));
    }
  }
 catch (  AxelorException e) {
    TraceBackService.trace(new AxelorException(String.format("String_Node_Str",batch.getId()),e,e.getcategory()),IException.DIRECT_DEBIT,batch.getId());
    incrementAnomaly();
  }
catch (  Exception e) {
    TraceBackService.trace(new Exception(String.format("String_Node_Str",batch.getId()),e),IException.DIRECT_DEBIT,batch.getId());
    incrementAnomaly();
    LOG.error("String_Node_Str",batch.getId());
  }
  return pslListToExport;
}

Fixed version (ground truth):
/** 
 * Méthode permettant de générer l'ensemble des exports des prélèvements pour Mensu
 * @param paymentScheduleExport Un objet d'export des prélèvements
 * @param company Une société
 * @param paymentMode Un mode de paiement
 * @param statusVal Un status
 * @param journal Un journal
 * @param isMajorAccount Le traitement concerne le prélèvement des échéances de mensu grand compte ?
 * @return 
 * @return
 * @throws AxelorException
 */
public List<PaymentScheduleLine> generateAllExportMensu(List<PaymentScheduleLine> pslList,Company company,PaymentMode paymentMode,Status statusVal,Journal journal){
  Move move=null;
  try {
    move=paymentScheduleExportService.createExportMensuMove(Journal.find(journal.getId()),Company.find(company.getId()),PaymentMode.find(paymentMode.getId()));
  }
 catch (  AxelorException e) {
    TraceBackService.trace(new AxelorException(String.format("String_Node_Str",batch.getId()),e,e.getcategory()),IException.DIRECT_DEBIT,batch.getId());
    incrementAnomaly();
    stop=true;
  }
catch (  Exception e) {
    TraceBackService.trace(new Exception(String.format("String_Node_Str",batch.getId()),e),IException.DIRECT_DEBIT,batch.getId());
    incrementAnomaly();
    LOG.error("String_Node_Str",batch.getId());
    stop=true;
  }
  int ref=1;
  int i=0;
  List<PaymentScheduleLine> pslListToExport=new ArrayList<PaymentScheduleLine>();
  if (!stop) {
    for (    PaymentScheduleLine paymentScheduleLine : pslList) {
      try {
        if (!paymentScheduleExportService.isDebitBlocking(paymentScheduleLine)) {
          PaymentScheduleLine paymentScheduleLineToExport=paymentScheduleExportService.generateExportMensu(PaymentScheduleLine.find(paymentScheduleLine.getId()),pslList,Status.find(statusVal.getId()),Company.find(company.getId()),ref,Move.find(move.getId()));
          if (paymentScheduleLineToExport != null) {
            ref++;
            i++;
            pslListToExport.add(paymentScheduleLineToExport);
            updatePaymentScheduleLine(paymentScheduleLineToExport);
            this.totalAmount=this.totalAmount.add(PaymentScheduleLine.find(paymentScheduleLine.getId()).getInTaxAmount());
          }
        }
      }
 catch (      AxelorException e) {
        TraceBackService.trace(new AxelorException(String.format("String_Node_Str",paymentScheduleLine.getName()),e,e.getcategory()),IException.DIRECT_DEBIT,batch.getId());
        incrementAnomaly();
      }
catch (      Exception e) {
        TraceBackService.trace(new Exception(String.format("String_Node_Str",paymentScheduleLine.getName()),e),IException.DIRECT_DEBIT,batch.getId());
        incrementAnomaly();
        LOG.error("String_Node_Str",paymentScheduleLine.getName());
      }
 finally {
        if (i % 10 == 0) {
          JPA.clear();
        }
      }
    }
  }
  try {
    if (ref != 1) {
      Account bankAccount=paymentModeService.getCompanyAccount(PaymentMode.find(paymentMode.getId()),Company.find(company.getId()));
      paymentScheduleExportService.createOppositeExportMensuMoveLine(Move.find(move.getId()),bankAccount,ref);
      paymentScheduleExportService.validateMove(Move.find(move.getId()));
    }
 else {
      paymentScheduleExportService.deleteMove(Move.find(move.getId()));
    }
  }
 catch (  AxelorException e) {
    TraceBackService.trace(new AxelorException(String.format("String_Node_Str",batch.getId()),e,e.getcategory()),IException.DIRECT_DEBIT,batch.getId());
    incrementAnomaly();
  }
catch (  Exception e) {
    TraceBackService.trace(new Exception(String.format("String_Node_Str",batch.getId()),e),IException.DIRECT_DEBIT,batch.getId());
    incrementAnomaly();
    LOG.error("String_Node_Str",batch.getId());
  }
  return pslListToExport;
}