From fdf33461b3314925f07916e6617028b2493e9ebb Mon Sep 17 00:00:00 2001 From: zubri Date: Wed, 14 Aug 2024 11:35:16 -0300 Subject: [PATCH] cherry pick PR CU-86b1kajgv_PW-1958--NullPointerException-in-MxSwiftMessageapplyStrategy --- CHANGELOG.md | 3 + .../model/mx/DefaultMxMetadataStrategy.java | 16 +-- .../com/prowidesoftware/issues/Issue1958.java | 114 ++++++++++++++++++ 3 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 iso20022-core/src/test/java/com/prowidesoftware/issues/Issue1958.java diff --git a/CHANGELOG.md b/CHANGELOG.md index bba82bfc3..6e25290d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Prowide ISO 20022 - CHANGELOG +#### 9.5.4 - August 2024 + * (PW-1958) Fixed the `DefaultMxMetadataStrategy` NPE issue when the amount values are null + #### 9.5.3 - August 2024 * (PW-1947) Updated MX model with latest SWIFT SRU2024 schema update, including new messages such as trck.001.001.03 * Add support for Business Application Header version head.001.001.04 diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/DefaultMxMetadataStrategy.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/DefaultMxMetadataStrategy.java index bfe91aa68..c8dcb53ea 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/DefaultMxMetadataStrategy.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/DefaultMxMetadataStrategy.java @@ -91,7 +91,7 @@ public Optional amount(AbstractMessage message) { private Money getCamt29Amount(MxNode document) { MxNode amount = document.findFirst("./RsltnOfInvstgtn/CxlDtls/OrgnlPmtInfAndSts/TxInfAndSts/OrgnlInstdAmt"); - if (amount != null) { + if (amount != null && amount.getValue() != null) { return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue())); } return null; @@ -99,7 +99,7 @@ private Money getCamt29Amount(MxNode document) { private Money getCamt52Amount(MxNode document) { MxNode amount = document.findFirst("./BkToCstmrAcctRpt/Rpt/Bal/Amt"); - if (amount != null) { + if (amount != null && amount.getValue() != null) { return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue())); } return null; @@ -107,7 +107,7 @@ private Money getCamt52Amount(MxNode document) { private Money getCamt53Amount(MxNode document) { MxNode amount = document.findFirst("./BkToCstmrStmt/Stmt/Bal/Amt"); - if (amount != null) { + if (amount != null && amount.getValue() != null) { return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue())); } return null; @@ -121,7 +121,7 @@ private Money getCamt54Amount(MxNode document) { if (amount == null) { amount = document.findFirst("./BkToCstmrDbtCdtNtfctn/Ntfctn/Ntry/NtryDtls/TxDtls/Amt"); } - if (amount != null) { + if (amount != null && amount.getValue() != null) { return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue())); } return null; @@ -129,7 +129,7 @@ private Money getCamt54Amount(MxNode document) { private Money getCamt56Amount(MxNode document) { MxNode amount = document.findFirst("./FIToFIPmtCxlReq/Undrlyg/TxInf/OrgnlIntrBkSttlmAmt"); - if (amount != null) { + if (amount != null && amount.getValue() != null) { return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue())); } return null; @@ -137,7 +137,7 @@ private Money getCamt56Amount(MxNode document) { private Money getCamt57Amount(MxNode document) { MxNode amount = document.findFirst("./NtfctnToRcv/Ntfctn/TtlAmt"); - if (amount != null) { + if (amount != null && amount.getValue() != null) { return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue())); } return null; @@ -148,7 +148,7 @@ private Money getPacs004Amount(MxNode document) { if (amount == null) { amount = document.findFirst("./PmtRtr/TxInf/RtrdIntrBkSttlmAmt"); } - if (amount != null) { + if (amount != null && amount.getValue() != null) { return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue())); } return null; @@ -181,7 +181,7 @@ private Money getPacsAmount(MxNode document) { MxNode cdtTrfNode = document.findFirstByName("CdtTrfTxInf"); if (cdtTrfNode != null) { MxNode amount = cdtTrfNode.findFirst("./IntrBkSttlmAmt"); - if (amount != null) { + if (amount != null && amount.getValue() != null) { return new Money(amount.getAttribute("Ccy"), new BigDecimal(amount.getValue())); } } diff --git a/iso20022-core/src/test/java/com/prowidesoftware/issues/Issue1958.java b/iso20022-core/src/test/java/com/prowidesoftware/issues/Issue1958.java new file mode 100644 index 000000000..a1ad67acf --- /dev/null +++ b/iso20022-core/src/test/java/com/prowidesoftware/issues/Issue1958.java @@ -0,0 +1,114 @@ +package com.prowidesoftware.issues; + +import static org.junit.jupiter.api.Assertions.fail; + +import com.prowidesoftware.swift.model.MxSwiftMessage; +import org.junit.jupiter.api.Test; + +public class Issue1958 { + + @Test + void test() { + try { + String xml = "" + + "" + + "" + + " " + + " BIC" + + " AAAANGL0XXX" + + " " + + " " + + " BIC" + + " BBBBUS33XXX" + + " " + + " pacs.008.001.08" + + " FOOBAR1" + + " 2022-05-05T06:07:14Z" + + "" + + "" + + " " + + " " + + " FOOBAR2" + + " 2022-05-05T06:07:14Z" + + " 1" + + " " + + " INDA" + + " " + + " " + + " " + + " 04435001" + + " " + + " " + + " " + + " " + + " " + + " " + + " AAAANGL0XXX" + + " " + + " " + + " " + + " " + + " BBBBUS33XXX" + + " " + + " " + + " " + + " " + + " " + + " REF333222333" + + " RRRR345345" + + " FFDD34534" + + " " + + " " + + " 2022-05-05" + + " " + + " DEBT" + + " " + + " FOO FEED MILLS COLTD" + + " " + + " 1 GOLDEN PENNY PLACE, WHARF ROAD," + + " APAPA LAGOS" + + " " + + " " + + " " + + " " + + " " + + " 2028766092" + + " " + + " " + + " " + + " " + + " " + + " AAAANGLA" + + " " + + " " + + " " + + " " + + " BBBBRU21" + + " " + + " " + + " " + + " TEST" + + " " + + " TEST" + + " " + + " " + + " " + + " " + + " " + + " TEST" + + " " + + " " + + " " + + " " + + " AGRICULTURAL SECTOR" + + " " + + " " + + " " + + "" + + ""; + new MxSwiftMessage(xml); + } catch (Exception e) { + fail(); + } + } +}