mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-25 07:10:48 -04:00
Add null checks
This commit is contained in:
parent
33682694ed
commit
3b75cc2fd0
5 changed files with 56 additions and 34 deletions
|
@ -2,8 +2,6 @@
|
||||||
Theme colors:
|
Theme colors:
|
||||||
|
|
||||||
logo colors:
|
logo colors:
|
||||||
blue: 0096c9
|
|
||||||
dark grey: #333333
|
|
||||||
|
|
||||||
new blue: 0f87c3
|
new blue: 0f87c3
|
||||||
new grey: 666666
|
new grey: 666666
|
||||||
|
|
|
@ -59,7 +59,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Domain for that UI element.
|
* Domain for that UI element.
|
||||||
|
@ -244,7 +244,7 @@ class CreateOfferDataModel implements Activatable, DataModel {
|
||||||
@SuppressWarnings("NullableProblems")
|
@SuppressWarnings("NullableProblems")
|
||||||
void setDirection(Direction direction) {
|
void setDirection(Direction direction) {
|
||||||
// direction can not be changed once it is initially set
|
// direction can not be changed once it is initially set
|
||||||
checkArgument(direction != null);
|
checkNotNull(direction);
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,15 +129,22 @@ class TakeOfferDataModel implements Activatable, DataModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
void takeOffer() {
|
void takeOffer() {
|
||||||
Trade trade = tradeManager.takeOffer(amountAsCoin.get(), offer);
|
final Trade trade = tradeManager.takeOffer(amountAsCoin.get(), offer);
|
||||||
trade.stateProperty().addListener((ov, oldValue, newValue) -> {
|
trade.stateProperty().addListener((ov, oldValue, newValue) -> {
|
||||||
log.debug("trade state = " + newValue);
|
log.debug("trade state = " + newValue);
|
||||||
switch (newValue) {
|
switch (newValue) {
|
||||||
// TODO Check why DEPOSIT_CONFIRMED can happen, refactor state handling
|
// TODO Check why DEPOSIT_CONFIRMED can happen, refactor state handling
|
||||||
case DEPOSIT_PUBLISHED:
|
case DEPOSIT_PUBLISHED:
|
||||||
case DEPOSIT_CONFIRMED:
|
case DEPOSIT_CONFIRMED:
|
||||||
|
// TODO null pointer happened here!
|
||||||
|
if (trade.getDepositTx() != null) {
|
||||||
transactionId.set(trade.getDepositTx().getHashAsString());
|
transactionId.set(trade.getDepositTx().getHashAsString());
|
||||||
requestTakeOfferSuccess.set(true);
|
requestTakeOfferSuccess.set(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.warn("trade.getDepositTx() = null. at trade state " + newValue +
|
||||||
|
" That should not happen and needs more investigation why it can happen.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case FAILED:
|
case FAILED:
|
||||||
requestTakeOfferErrorMessage.set("An error occurred. Error: " + trade.getFault().getMessage());
|
requestTakeOfferErrorMessage.set("An error occurred. Error: " + trade.getFault().getMessage());
|
||||||
|
|
|
@ -418,7 +418,7 @@ public class TradeManager {
|
||||||
log.trace("onIncomingTradeMessage sender " + sender);
|
log.trace("onIncomingTradeMessage sender " + sender);
|
||||||
|
|
||||||
String tradeId = tradeMessage.getTradeId();
|
String tradeId = tradeMessage.getTradeId();
|
||||||
|
if (tradeId != null) {
|
||||||
if (tradeMessage instanceof RequestTakeOfferMessage) {
|
if (tradeMessage instanceof RequestTakeOfferMessage) {
|
||||||
createOffererAsBuyerProtocol(tradeId, sender);
|
createOffererAsBuyerProtocol(tradeId, sender);
|
||||||
}
|
}
|
||||||
|
@ -427,7 +427,8 @@ public class TradeManager {
|
||||||
(RespondToTakeOfferRequestMessage) tradeMessage);
|
(RespondToTakeOfferRequestMessage) tradeMessage);
|
||||||
}
|
}
|
||||||
else if (tradeMessage instanceof TakeOfferFeePayedMessage) {
|
else if (tradeMessage instanceof TakeOfferFeePayedMessage) {
|
||||||
offererAsBuyerProtocolMap.get(tradeId).onTakeOfferFeePayedMessage((TakeOfferFeePayedMessage) tradeMessage);
|
offererAsBuyerProtocolMap.get(tradeId).onTakeOfferFeePayedMessage((TakeOfferFeePayedMessage)
|
||||||
|
tradeMessage);
|
||||||
}
|
}
|
||||||
else if (tradeMessage instanceof RequestTakerDepositPaymentMessage) {
|
else if (tradeMessage instanceof RequestTakerDepositPaymentMessage) {
|
||||||
takerAsSellerProtocolMap.get(tradeId).onRequestTakerDepositPaymentMessage(
|
takerAsSellerProtocolMap.get(tradeId).onRequestTakerDepositPaymentMessage(
|
||||||
|
@ -439,13 +440,26 @@ public class TradeManager {
|
||||||
}
|
}
|
||||||
else if (tradeMessage instanceof DepositTxPublishedMessage) {
|
else if (tradeMessage instanceof DepositTxPublishedMessage) {
|
||||||
persistPendingTrades();
|
persistPendingTrades();
|
||||||
takerAsSellerProtocolMap.get(tradeId).onDepositTxPublishedMessage((DepositTxPublishedMessage) tradeMessage);
|
takerAsSellerProtocolMap.get(tradeId).onDepositTxPublishedMessage((DepositTxPublishedMessage)
|
||||||
|
tradeMessage);
|
||||||
}
|
}
|
||||||
else if (tradeMessage instanceof BankTransferInitedMessage) {
|
else if (tradeMessage instanceof BankTransferInitedMessage) {
|
||||||
takerAsSellerProtocolMap.get(tradeId).onBankTransferInitedMessage((BankTransferInitedMessage) tradeMessage);
|
// Here happened a null pointer. I assume the only possible reason was that we got a null for the
|
||||||
|
// tradeID
|
||||||
|
// as the takerAsSellerProtocolMap need to have that trade got added earlier.
|
||||||
|
// For getting better info we add a check. tradeId is checked above.
|
||||||
|
if (takerAsSellerProtocolMap.get(tradeId) == null)
|
||||||
|
log.error("takerAsSellerProtocolMap.get(tradeId) = null. That must not happen.");
|
||||||
|
takerAsSellerProtocolMap.get(tradeId).onBankTransferInitedMessage((BankTransferInitedMessage)
|
||||||
|
tradeMessage);
|
||||||
}
|
}
|
||||||
else if (tradeMessage instanceof PayoutTxPublishedMessage) {
|
else if (tradeMessage instanceof PayoutTxPublishedMessage) {
|
||||||
offererAsBuyerProtocolMap.get(tradeId).onPayoutTxPublishedMessage((PayoutTxPublishedMessage) tradeMessage);
|
offererAsBuyerProtocolMap.get(tradeId).onPayoutTxPublishedMessage((PayoutTxPublishedMessage)
|
||||||
|
tradeMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.error("tradeId from onIncomingTradeMessage is null. That must not happen.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,9 @@ public class BuyerAcceptsOfferProtocol {
|
||||||
tradeId = trade.getId();
|
tradeId = trade.getId();
|
||||||
offer = trade.getOffer();
|
offer = trade.getOffer();
|
||||||
|
|
||||||
|
checkNotNull(tradeId);
|
||||||
|
checkNotNull(offer);
|
||||||
|
|
||||||
//TODO use first for now
|
//TODO use first for now
|
||||||
arbitratorPubKey = offer.getArbitrators().get(0).getPubKeyAsHex();
|
arbitratorPubKey = offer.getArbitrators().get(0).getPubKeyAsHex();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue