Program: 58624
Project: 58624
Buggy source:
/** 
 * Method to create an XML file for SEPA transfer pain.001.001.02
 * @throws AxelorException
 * @throws DatatypeConfigurationException
 * @throws JAXBException
 * @throws IOException
 */
@Override public File generateFile() throws JAXBException, IOException, AxelorException, DatatypeConfigurationException {
  DatatypeFactory datatypeFactory=DatatypeFactory.newInstance();
  ObjectFactory factory=new ObjectFactory();
  ServiceLevel2Choice svcLvl=factory.createServiceLevel2Choice();
  svcLvl.setCd(ServiceLevel1Code.SEPA);
  PaymentTypeInformation1 pmtTpInf=factory.createPaymentTypeInformation1();
  pmtTpInf.setSvcLvl(svcLvl);
  PartyIdentification8 dbtr=factory.createPartyIdentification8();
  dbtr.setNm(senderBankDetails.getOwnerName());
  AccountIdentification3Choice iban=factory.createAccountIdentification3Choice();
  iban.setIBAN(senderBankDetails.getIban());
  CashAccount7 dbtrAcct=factory.createCashAccount7();
  dbtrAcct.setId(iban);
  FinancialInstitutionIdentification5Choice finInstnId=factory.createFinancialInstitutionIdentification5Choice();
  finInstnId.setBIC(senderBankDetails.getBank().getCode());
  BranchAndFinancialInstitutionIdentification3 dbtrAgt=factory.createBranchAndFinancialInstitutionIdentification3();
  dbtrAgt.setFinInstnId(finInstnId);
  PaymentInstructionInformation1 pmtInf=factory.createPaymentInstructionInformation1();
  pmtInf.setPmtInfId(bankOrderSeq);
  pmtInf.setPmtMtd(PaymentMethod3Code.TRF);
  pmtInf.setPmtTpInf(pmtTpInf);
  pmtInf.setReqdExctnDt(datatypeFactory.newXMLGregorianCalendar(bankOrderDate.toString("String_Node_Str")));
  pmtInf.setDbtr(dbtr);
  pmtInf.setDbtrAcct(dbtrAcct);
  pmtInf.setDbtrAgt(dbtrAgt);
  CreditTransferTransactionInformation1 cdtTrfTxInf=null;
  PaymentIdentification1 pmtId=null;
  AmountType2Choice amt=null;
  CurrencyAndAmount instdAmt=null;
  PartyIdentification8 cbtr=null;
  CashAccount7 cbtrAcct=null;
  BranchAndFinancialInstitutionIdentification3 cbtrAgt=null;
  RemittanceInformation1 rmtInf=null;
  for (  BankOrderLine bankOrderLine : bankOrderLineList) {
    BankDetails receiverBankDetails=bankOrderLine.getReceiverBankDetails();
    pmtId=factory.createPaymentIdentification1();
    pmtId.setEndToEndId(bankOrderLine.getSequence());
    instdAmt=factory.createCurrencyAndAmount();
    instdAmt.setCcy(bankOrderCurrency.getCode());
    instdAmt.setValue(bankOrderLine.getBankOrderAmount());
    amt=factory.createAmountType2Choice();
    amt.setInstdAmt(instdAmt);
    cbtr=factory.createPartyIdentification8();
    cbtr.setNm(receiverBankDetails.getOwnerName());
    iban=factory.createAccountIdentification3Choice();
    iban.setIBAN(receiverBankDetails.getIban());
    cbtrAcct=factory.createCashAccount7();
    cbtrAcct.setId(iban);
    finInstnId=factory.createFinancialInstitutionIdentification5Choice();
    finInstnId.setBIC(receiverBankDetails.getBank().getCode());
    cbtrAgt=factory.createBranchAndFinancialInstitutionIdentification3();
    cbtrAgt.setFinInstnId(finInstnId);
    rmtInf=factory.createRemittanceInformation1();
    String ustrd=bankOrderLine.getReceiverReference();
    if (!Strings.isNullOrEmpty(ustrd)) {
      ustrd+="String_Node_Str";
    }
    ustrd+=bankOrderLine.getReceiverLabel();
    rmtInf.getUstrd().add(ustrd);
    cdtTrfTxInf=factory.createCreditTransferTransactionInformation1();
    cdtTrfTxInf.setPmtId(pmtId);
    cdtTrfTxInf.setAmt(amt);
    cdtTrfTxInf.setCdtr(cbtr);
    cdtTrfTxInf.setCdtrAcct(cbtrAcct);
    cdtTrfTxInf.setCdtrAgt(cbtrAgt);
    cdtTrfTxInf.setRmtInf(rmtInf);
    pmtInf.getCdtTrfTxInf().add(cdtTrfTxInf);
  }
  GroupHeader1 grpHdr=factory.createGroupHeader1();
  grpHdr.setMsgId(bankOrderSeq);
  grpHdr.setCreDtTm(datatypeFactory.newXMLGregorianCalendar(generationDateTime.toString("String_Node_Str")));
  grpHdr.setNbOfTxs(Integer.toString(nbOfLines));
  grpHdr.setCtrlSum(arithmeticTotal);
  grpHdr.setGrpg(Grouping1Code.MIXD);
  grpHdr.setInitgPty(dbtr);
  Pain00100102 pain00100102=factory.createPain00100102();
  pain00100102.setGrpHdr(grpHdr);
  pain00100102.getPmtInf().add(pmtInf);
  Document xml=factory.createDocument();
  xml.setPain00100102(pain00100102);
  fileToCreate=factory.createDocument(xml);
  return super.generateFile();
}

Fixed version (ground truth):
/** 
 * Method to create an XML file for SEPA transfer pain.001.001.02
 * @throws AxelorException
 * @throws DatatypeConfigurationException
 * @throws JAXBException
 * @throws IOException
 */
@Override public File generateFile() throws JAXBException, IOException, AxelorException, DatatypeConfigurationException {
  DatatypeFactory datatypeFactory=DatatypeFactory.newInstance();
  ObjectFactory factory=new ObjectFactory();
  ServiceLevel2Choice svcLvl=factory.createServiceLevel2Choice();
  svcLvl.setCd(ServiceLevel1Code.SEPA);
  PaymentTypeInformation1 pmtTpInf=factory.createPaymentTypeInformation1();
  pmtTpInf.setSvcLvl(svcLvl);
  PartyIdentification8 dbtr=factory.createPartyIdentification8();
  dbtr.setNm(senderBankDetails.getOwnerName());
  AccountIdentification3Choice iban=factory.createAccountIdentification3Choice();
  iban.setIBAN(senderBankDetails.getIban());
  CashAccount7 dbtrAcct=factory.createCashAccount7();
  dbtrAcct.setId(iban);
  FinancialInstitutionIdentification5Choice finInstnId=factory.createFinancialInstitutionIdentification5Choice();
  finInstnId.setBIC(senderBankDetails.getBank().getCode());
  BranchAndFinancialInstitutionIdentification3 dbtrAgt=factory.createBranchAndFinancialInstitutionIdentification3();
  dbtrAgt.setFinInstnId(finInstnId);
  PaymentInstructionInformation1 pmtInf=factory.createPaymentInstructionInformation1();
  pmtInf.setPmtInfId(bankOrderSeq);
  pmtInf.setPmtMtd(PaymentMethod3Code.TRF);
  pmtInf.setPmtTpInf(pmtTpInf);
  pmtInf.setReqdExctnDt(datatypeFactory.newXMLGregorianCalendar(bankOrderDate.toString("String_Node_Str")));
  pmtInf.setDbtr(dbtr);
  pmtInf.setDbtrAcct(dbtrAcct);
  pmtInf.setDbtrAgt(dbtrAgt);
  CreditTransferTransactionInformation1 cdtTrfTxInf=null;
  PaymentIdentification1 pmtId=null;
  AmountType2Choice amt=null;
  CurrencyAndAmount instdAmt=null;
  PartyIdentification8 cbtr=null;
  CashAccount7 cbtrAcct=null;
  BranchAndFinancialInstitutionIdentification3 cbtrAgt=null;
  RemittanceInformation1 rmtInf=null;
  for (  BankOrderLine bankOrderLine : bankOrderLineList) {
    BankDetails receiverBankDetails=bankOrderLine.getReceiverBankDetails();
    pmtId=factory.createPaymentIdentification1();
    pmtId.setEndToEndId(bankOrderLine.getSequence());
    instdAmt=factory.createCurrencyAndAmount();
    instdAmt.setCcy(bankOrderCurrency.getCode());
    instdAmt.setValue(bankOrderLine.getBankOrderAmount());
    amt=factory.createAmountType2Choice();
    amt.setInstdAmt(instdAmt);
    cbtr=factory.createPartyIdentification8();
    cbtr.setNm(receiverBankDetails.getOwnerName());
    iban=factory.createAccountIdentification3Choice();
    iban.setIBAN(receiverBankDetails.getIban());
    cbtrAcct=factory.createCashAccount7();
    cbtrAcct.setId(iban);
    finInstnId=factory.createFinancialInstitutionIdentification5Choice();
    finInstnId.setBIC(receiverBankDetails.getBank().getCode());
    cbtrAgt=factory.createBranchAndFinancialInstitutionIdentification3();
    cbtrAgt.setFinInstnId(finInstnId);
    rmtInf=factory.createRemittanceInformation1();
    String ustrd="String_Node_Str";
    if (!Strings.isNullOrEmpty(bankOrderLine.getReceiverReference())) {
      ustrd+=bankOrderLine.getReceiverReference();
    }
    if (!Strings.isNullOrEmpty(bankOrderLine.getReceiverLabel())) {
      if (!Strings.isNullOrEmpty(ustrd)) {
        ustrd+="String_Node_Str";
      }
      ustrd+=bankOrderLine.getReceiverLabel();
    }
    rmtInf.getUstrd().add(ustrd);
    cdtTrfTxInf=factory.createCreditTransferTransactionInformation1();
    cdtTrfTxInf.setPmtId(pmtId);
    cdtTrfTxInf.setAmt(amt);
    cdtTrfTxInf.setCdtr(cbtr);
    cdtTrfTxInf.setCdtrAcct(cbtrAcct);
    cdtTrfTxInf.setCdtrAgt(cbtrAgt);
    cdtTrfTxInf.setRmtInf(rmtInf);
    pmtInf.getCdtTrfTxInf().add(cdtTrfTxInf);
  }
  GroupHeader1 grpHdr=factory.createGroupHeader1();
  grpHdr.setMsgId(bankOrderSeq);
  grpHdr.setCreDtTm(datatypeFactory.newXMLGregorianCalendar(generationDateTime.toString("String_Node_Str")));
  grpHdr.setNbOfTxs(Integer.toString(nbOfLines));
  grpHdr.setCtrlSum(arithmeticTotal);
  grpHdr.setGrpg(Grouping1Code.MIXD);
  grpHdr.setInitgPty(dbtr);
  Pain00100102 pain00100102=factory.createPain00100102();
  pain00100102.setGrpHdr(grpHdr);
  pain00100102.getPmtInf().add(pmtInf);
  Document xml=factory.createDocument();
  xml.setPain00100102(pain00100102);
  fileToCreate=factory.createDocument(xml);
  return super.generateFile();
}