Program: 58902
Project: 58902
Buggy source:
public void getDiscount(ActionRequest request,ActionResponse response){
  PurchaseOrderLine purchaseOrderLine=request.getContext().asType(PurchaseOrderLine.class);
  PurchaseOrder purchaseOrder=purchaseOrderLine.getPurchaseOrder();
  if (purchaseOrder == null) {
    purchaseOrder=request.getContext().getParentContext().asType(PurchaseOrder.class);
  }
  if (purchaseOrder != null && purchaseOrderLine.getProduct() != null) {
    try {
      BigDecimal price=purchaseOrderLine.getPrice();
      if (price.compareTo(BigDecimal.ZERO) == 0) {
        price=purchaseOrderLine.getProduct().getPurchasePrice();
      }
      PriceList priceList=purchaseOrder.getPriceList();
      int discountTypeSelect=0;
      BigDecimal discountAmount=BigDecimal.ZERO;
      if (priceList != null) {
        PriceListLine priceListLine=purchaseOrderLineService.getPriceListLine(purchaseOrderLine,priceList);
        if (priceListLine != null) {
          discountTypeSelect=priceListLine.getTypeSelect();
        }
        if ((GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountTypeSelect == IPriceListLine.TYPE_REPLACE) || GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.INCLUDE_DISCOUNT) {
          Map<String,Object> discounts=priceListService.getDiscounts(priceList,priceListLine,price);
          discountAmount=(BigDecimal)discounts.get("String_Node_Str");
          price=priceListService.computeDiscount(price,(int)discounts.get("String_Node_Str"),discountAmount);
        }
 else {
          Map<String,Object> discounts=priceListService.getDiscounts(priceList,priceListLine,price);
          discountAmount=(BigDecimal)discounts.get("String_Node_Str");
          response.setValue("String_Node_Str",discountAmount);
          response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
          if (discounts.get("String_Node_Str") != null) {
            price=(BigDecimal)discounts.get("String_Node_Str");
          }
        }
      }
      if (discountAmount.equals(BigDecimal.ZERO)) {
        List<SupplierCatalog> supplierCatalogList=purchaseOrderLine.getProduct().getSupplierCatalogList();
        if (supplierCatalogList != null && !supplierCatalogList.isEmpty()) {
          SupplierCatalog supplierCatalog=Beans.get(SupplierCatalogRepository.class).all().filter("String_Node_Str",purchaseOrderLine.getProduct(),purchaseOrderLine.getQty(),purchaseOrder.getSupplierPartner()).fetchOne();
          if (supplierCatalog != null) {
            if (GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.DISCOUNT_SEPARATE) {
              Map<String,Object> discounts=productService.getDiscountsFromCatalog(supplierCatalog,price);
              response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
              response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
            }
 else {
              Map<String,Object> discounts=productService.getDiscountsFromCatalog(supplierCatalog,price);
              price=priceListService.computeDiscount(price,(int)discounts.get("String_Node_Str"),(BigDecimal)discounts.get("String_Node_Str"));
            }
          }
        }
      }
      response.setValue("String_Node_Str",price);
    }
 catch (    Exception e) {
      response.setFlash(e.getMessage());
    }
  }
}

Fixed version (ground truth):
public void getDiscount(ActionRequest request,ActionResponse response){
  PurchaseOrderLine purchaseOrderLine=request.getContext().asType(PurchaseOrderLine.class);
  PurchaseOrder purchaseOrder=purchaseOrderLine.getPurchaseOrder();
  if (purchaseOrder == null) {
    purchaseOrder=request.getContext().getParentContext().asType(PurchaseOrder.class);
  }
  if (purchaseOrder != null && purchaseOrderLine.getProduct() != null) {
    try {
      BigDecimal price=purchaseOrderLine.getPrice();
      PriceList priceList=purchaseOrder.getPriceList();
      int discountTypeSelect=0;
      BigDecimal discountAmount=BigDecimal.ZERO;
      if (priceList != null) {
        PriceListLine priceListLine=purchaseOrderLineService.getPriceListLine(purchaseOrderLine,priceList);
        if (priceListLine != null) {
          discountTypeSelect=priceListLine.getTypeSelect();
        }
        if ((GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountTypeSelect == IPriceListLine.TYPE_REPLACE) || GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.INCLUDE_DISCOUNT) {
          Map<String,Object> discounts=priceListService.getDiscounts(priceList,priceListLine,price);
          discountAmount=(BigDecimal)discounts.get("String_Node_Str");
          price=priceListService.computeDiscount(price,(int)discounts.get("String_Node_Str"),discountAmount);
        }
 else {
          Map<String,Object> discounts=priceListService.getDiscounts(priceList,priceListLine,price);
          discountAmount=(BigDecimal)discounts.get("String_Node_Str");
          response.setValue("String_Node_Str",discountAmount);
          response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
          if (discounts.get("String_Node_Str") != null) {
            price=(BigDecimal)discounts.get("String_Node_Str");
          }
        }
      }
      if (discountAmount.equals(BigDecimal.ZERO)) {
        List<SupplierCatalog> supplierCatalogList=purchaseOrderLine.getProduct().getSupplierCatalogList();
        if (supplierCatalogList != null && !supplierCatalogList.isEmpty()) {
          SupplierCatalog supplierCatalog=Beans.get(SupplierCatalogRepository.class).all().filter("String_Node_Str",purchaseOrderLine.getProduct(),purchaseOrderLine.getQty(),purchaseOrder.getSupplierPartner()).fetchOne();
          if (supplierCatalog != null) {
            if (GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.DISCOUNT_SEPARATE) {
              Map<String,Object> discounts=productService.getDiscountsFromCatalog(supplierCatalog,price);
              response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
              response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
            }
 else {
              Map<String,Object> discounts=productService.getDiscountsFromCatalog(supplierCatalog,price);
              price=priceListService.computeDiscount(price,(int)discounts.get("String_Node_Str"),(BigDecimal)discounts.get("String_Node_Str"));
            }
          }
        }
      }
      response.setValue("String_Node_Str",price);
    }
 catch (    Exception e) {
      response.setFlash(e.getMessage());
    }
  }
}