Program: 59031
Project: 59031
Buggy source:
@Transactional void validateSaleOrder(Long soId){
  try {
    SaleOrder saleOrder=SaleOrder.find(soId);
    for (    SaleOrderLine line : saleOrder.getSaleOrderLineList())     line.setTaxLine(saleOrderLineService.getTaxLine(saleOrder,line));
    saleOrderService.computeSaleOrder(saleOrder);
    if (saleOrder.getStatusSelect() == 3) {
      taskSaleOrderService.createTasks(saleOrder);
      saleOrderServiceStockImpl.createStocksMovesFromSaleOrder(saleOrder);
      saleOrderPurchaseService.createPurchaseOrders(saleOrder);
      saleOrder.setClientPartner(saleOrderService.validateCustomer(saleOrder));
      if (saleOrder.getInvoicingTypeSelect() == 1 || saleOrder.getInvoicingTypeSelect() == 5) {
        Invoice invoice=saleOrderInvoiceService.generatePerOrderInvoice(saleOrder);
        invoice.setInvoiceDate(saleOrder.getValidationDate());
        invoiceService.compute(invoice);
        invoiceService.validate(invoice);
        invoiceService.ventilate(invoice);
      }
      StockMove stockMove=StockMove.all_().filter("String_Node_Str",saleOrder).fetchOne();
      if (stockMove != null && stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
        stockMoveService.copyQtyToRealQty(stockMove);
        stockMoveService.validate(stockMove);
        stockMove.setRealDate(saleOrder.getValidationDate());
        if (saleOrder.getInvoicingTypeSelect() == 4) {
          Invoice invoice=stockMoveInvoiceService.createInvoiceFromSaleOrder(stockMove,saleOrder);
          invoice.setInvoiceDate(saleOrder.getValidationDate());
          invoiceService.compute(invoice);
          invoiceService.validate(invoice);
          invoiceService.ventilate(invoice);
        }
      }
    }
    saleOrder.save();
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
@Transactional void validateSaleOrder(Long soId){
  try {
    SaleOrder saleOrder=SaleOrder.find(soId);
    for (    SaleOrderLine line : saleOrder.getSaleOrderLineList())     line.setTaxLine(saleOrderLineService.getTaxLine(saleOrder,line));
    saleOrderService.computeSaleOrder(saleOrder);
    if (saleOrder.getStatusSelect() == 3) {
      taskSaleOrderService.createTasks(saleOrder);
      saleOrderServiceStockImpl.createStocksMovesFromSaleOrder(saleOrder);
      saleOrderPurchaseService.createPurchaseOrders(saleOrder);
      saleOrder.setClientPartner(saleOrderService.validateCustomer(saleOrder));
      if (saleOrder.getInvoicingTypeSelect() == 1 || saleOrder.getInvoicingTypeSelect() == 5) {
        Invoice invoice=saleOrderInvoiceService.generatePerOrderInvoice(saleOrder);
        invoice.setInvoiceDate(saleOrder.getValidationDate());
        invoiceService.compute(invoice);
        invoiceService.validate(invoice);
        invoiceService.ventilate(invoice);
      }
      StockMove stockMove=StockMove.all().filter("String_Node_Str",saleOrder).fetchOne();
      if (stockMove != null && stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
        stockMoveService.copyQtyToRealQty(stockMove);
        stockMoveService.validate(stockMove);
        stockMove.setRealDate(saleOrder.getValidationDate());
        if (saleOrder.getInvoicingTypeSelect() == 4) {
          Invoice invoice=stockMoveInvoiceService.createInvoiceFromSaleOrder(stockMove,saleOrder);
          invoice.setInvoiceDate(saleOrder.getValidationDate());
          invoiceService.compute(invoice);
          invoiceService.validate(invoice);
          invoiceService.ventilate(invoice);
        }
      }
    }
    saleOrder.save();
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}