Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in trader chat #5175

Merged
merged 1 commit into from Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/src/main/java/bisq/core/support/SupportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -191,7 +192,10 @@ private void onAckMessage(AckMessage ackMessage) {
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());

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/support/SupportSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public boolean isClient() {

public abstract String getTradeId();

public abstract PubKeyRing getClientPubKeyRing();
public abstract int getClientId();

public abstract ObservableList<ChatMessage> getObservableChatMessageList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ public String getTradeId() {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public String getTradeId() {
}

@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
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ private ChatMessage sendDisputeDirectMessage(String text, ArrayList<Attachment>
ChatMessage message = new ChatMessage(
supportManager.getSupportType(),
supportSession.getTradeId(),
supportSession.getClientPubKeyRing().hashCode(),
supportSession.getClientId(),
supportSession.isClient(),
text,
supportManager.getMyAddress(),
Expand Down