From ed78d0fbb41c4adaa5278eb85b9ef24b5d0cfe49 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Mon, 8 Feb 2021 17:35:56 -0600 Subject: [PATCH] Fix NPE when sending trader chat Show error message to user when trader chat message cannot be sent. --- .../main/java/bisq/core/support/SupportManager.java | 6 +++++- .../main/java/bisq/core/support/SupportSession.java | 2 +- .../bisq/core/support/dispute/DisputeSession.java | 9 +++++++-- .../core/support/traderchat/TradeChatSession.java | 11 +++++++---- .../src/main/resources/i18n/displayStrings.properties | 1 + .../main/java/bisq/desktop/main/shared/ChatView.java | 2 +- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/bisq/core/support/SupportManager.java b/core/src/main/java/bisq/core/support/SupportManager.java index 82ecc106d3..d353ed0606 100644 --- a/core/src/main/java/bisq/core/support/SupportManager.java +++ b/core/src/main/java/bisq/core/support/SupportManager.java @@ -18,6 +18,7 @@ package bisq.core.support; import bisq.core.btc.setup.WalletsSetup; +import bisq.core.locale.Res; import bisq.core.support.messages.ChatMessage; import bisq.core.support.messages.SupportMessage; @@ -191,7 +192,10 @@ public abstract class SupportManager { public ChatMessage sendChatMessage(ChatMessage message) { NodeAddress peersNodeAddress = getPeerNodeAddress(message); PubKeyRing receiverPubKeyRing = getPeerPubKeyRing(message); - if (receiverPubKeyRing != null) { + if (peersNodeAddress == null || receiverPubKeyRing == null) { + UserThread.runAfter(() -> + message.setSendMessageError(Res.get("support.receiverNotKnown")), 1); + } else { log.info("Send {} to peer {}. tradeId={}, uid={}", message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); diff --git a/core/src/main/java/bisq/core/support/SupportSession.java b/core/src/main/java/bisq/core/support/SupportSession.java index b4df4ed0b1..0354ddba7f 100644 --- a/core/src/main/java/bisq/core/support/SupportSession.java +++ b/core/src/main/java/bisq/core/support/SupportSession.java @@ -46,7 +46,7 @@ public abstract class SupportSession { public abstract String getTradeId(); - public abstract PubKeyRing getClientPubKeyRing(); + public abstract int getClientId(); public abstract ObservableList getObservableChatMessageList(); diff --git a/core/src/main/java/bisq/core/support/dispute/DisputeSession.java b/core/src/main/java/bisq/core/support/dispute/DisputeSession.java index cebe715e16..d381a0eaaf 100644 --- a/core/src/main/java/bisq/core/support/dispute/DisputeSession.java +++ b/core/src/main/java/bisq/core/support/dispute/DisputeSession.java @@ -57,9 +57,14 @@ public abstract class DisputeSession extends SupportSession { } @Override - public PubKeyRing getClientPubKeyRing() { + public int getClientId() { // Get pubKeyRing of trader. Arbitrator is considered server for the chat session - return dispute != null ? dispute.getTraderPubKeyRing() : null; + try { + return dispute.getTraderPubKeyRing().hashCode(); + } catch (NullPointerException e) { + log.warn("Unable to get traderPubKeyRing from Dispute - {}", e.toString()); + } + return 0; } @Override diff --git a/core/src/main/java/bisq/core/support/traderchat/TradeChatSession.java b/core/src/main/java/bisq/core/support/traderchat/TradeChatSession.java index c465d5ff72..e69a18c3f6 100644 --- a/core/src/main/java/bisq/core/support/traderchat/TradeChatSession.java +++ b/core/src/main/java/bisq/core/support/traderchat/TradeChatSession.java @@ -48,12 +48,15 @@ public class TradeChatSession extends SupportSession { } @Override - public PubKeyRing getClientPubKeyRing() { + public int getClientId() { // TODO remove that client-server concept for trade chat // Get pubKeyRing of taker. Maker is considered server for chat sessions - if (trade != null && trade.getContract() != null) - return trade.getContract().getTakerPubKeyRing(); - return null; + try { + return trade.getContract().getTakerPubKeyRing().hashCode(); + } catch (NullPointerException e) { + log.warn("Unable to get takerPubKeyRing from Trade Contract - {}", e.toString()); + } + return 0; } @Override diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 3fb90eea1e..fa99297c75 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -1105,6 +1105,7 @@ support.noTickets=There are no open tickets support.sendingMessage=Sending Message... support.receiverNotOnline=Receiver is not online. Message is saved to their mailbox. support.sendMessageError=Sending message failed. Error: {0} +support.receiverNotKnown=Receiver not known support.wrongVersion=The offer in that dispute has been created with an older version of Bisq.\n\ You cannot close that dispute with your version of the application.\n\n\ Please use an older version with protocol version {0} diff --git a/desktop/src/main/java/bisq/desktop/main/shared/ChatView.java b/desktop/src/main/java/bisq/desktop/main/shared/ChatView.java index 60d49a067f..6c53d843c8 100644 --- a/desktop/src/main/java/bisq/desktop/main/shared/ChatView.java +++ b/desktop/src/main/java/bisq/desktop/main/shared/ChatView.java @@ -648,7 +648,7 @@ public class ChatView extends AnchorPane { ChatMessage message = new ChatMessage( supportManager.getSupportType(), supportSession.getTradeId(), - supportSession.getClientPubKeyRing().hashCode(), + supportSession.getClientId(), supportSession.isClient(), text, supportManager.getMyAddress(),