From 7aa61fb6b08adc1a477e4259c7ad722ca0c59d3b Mon Sep 17 00:00:00 2001 From: Chris Parker Date: Tue, 24 Sep 2024 04:55:14 -0400 Subject: [PATCH] Improve exception msg and handling when 'Same Bank' BIC/SWIFT blank Users in most countries (see BankUtil.useValidation() ) can create a "Transfer Same Bank" account with no BIC/SWIFT code. However, to create an offer using this account, it must have a bankId or JAVA will throw a 'null pointer exception', and the app. will become unhealthy and hang trying on exit. This fix adds a validation check for the condition and throws a more "friendly" exception which explains the problem and keeps the app. healthy. --- core/src/main/java/bisq/core/offer/OfferUtil.java | 9 ++++++++- .../java/bisq/core/offer/bisq_v1/CreateOfferService.java | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index 708df4eecf9..5be68bc4263 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -30,6 +30,8 @@ import bisq.core.payment.CashByMailAccount; import bisq.core.payment.F2FAccount; import bisq.core.payment.PaymentAccount; +import bisq.core.payment.SameBankAccount; +import bisq.core.payment.SpecificBanksAccount; import bisq.core.payment.payload.PaymentMethod; import bisq.core.provider.fee.FeeService; import bisq.core.provider.price.MarketPrice; @@ -60,6 +62,7 @@ import javax.inject.Singleton; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -389,7 +392,8 @@ public Map getExtraDataMap(PaymentAccount paymentAccount, public void validateOfferData(double buyerSecurityDeposit, PaymentAccount paymentAccount, String currencyCode, - Coin makerFeeAsCoin) { + Coin makerFeeAsCoin, + List acceptedBanks) { validateBasicOfferData(paymentAccount.getPaymentMethod(), currencyCode); checkNotNull(makerFeeAsCoin, "makerFee must not be null"); checkArgument(buyerSecurityDeposit <= getMaxBuyerSecurityDepositAsPercent(), @@ -398,6 +402,9 @@ public void validateOfferData(double buyerSecurityDeposit, checkArgument(buyerSecurityDeposit >= getMinBuyerSecurityDepositAsPercent(), "securityDeposit must not be less than " + getMinBuyerSecurityDepositAsPercent()); + if ((paymentAccount instanceof SameBankAccount) || (paymentAccount instanceof SpecificBanksAccount) ) { + checkArgument(!acceptedBanks.contains(null), "acceptedBanks must not be null for SAME_BANK or SPECIFIC_BANKS accounts"); + } } public void validateBasicOfferData(PaymentMethod paymentMethod, String currencyCode) { diff --git a/core/src/main/java/bisq/core/offer/bisq_v1/CreateOfferService.java b/core/src/main/java/bisq/core/offer/bisq_v1/CreateOfferService.java index f984dd9ddff..8288ef92678 100644 --- a/core/src/main/java/bisq/core/offer/bisq_v1/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/bisq_v1/CreateOfferService.java @@ -177,7 +177,8 @@ public Offer createAndGetOffer(String offerId, buyerSecurityDepositAsDouble, paymentAccount, currencyCode, - makerFeeAsCoin); + makerFeeAsCoin, + acceptedBanks); OfferPayload offerPayload = new OfferPayload(offerId, creationTime,