Fix null pointers, improve logs

This commit is contained in:
Manfred Karrer 2017-02-24 15:03:26 -05:00
parent 972721cdba
commit f5d05f0940
5 changed files with 26 additions and 15 deletions

View file

@ -548,8 +548,9 @@ public class BtcWalletService extends WalletService {
"Missing " + (e.missing != null ? e.missing.toFriendlyString() : "null"));
}
} else {
log.warn("sendResult is null");
errorMessageHandler.handleErrorMessage("We could not find inputs we control in the transaction we want to double spend.");
String errorMessage = "We could not find inputs we control in the transaction we want to double spend.";
log.warn(errorMessage);
errorMessageHandler.handleErrorMessage(errorMessage);
}
} else if (confidenceType == TransactionConfidence.ConfidenceType.BUILDING) {
errorMessageHandler.handleErrorMessage("That transaction is already in the blockchain so we cannot double spend it.");

View file

@ -23,6 +23,7 @@ import io.bitsquare.locale.TradeCurrency;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -80,6 +81,7 @@ public abstract class PaymentAccount implements Persistable {
setSelectedTradeCurrency(tradeCurrency);
}
@Nullable
public TradeCurrency getSingleTradeCurrency() {
if (!tradeCurrencies.isEmpty())
return tradeCurrencies.get(0);

View file

@ -96,11 +96,12 @@ public class CryptoCurrencyForm extends PaymentMethodForm {
@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) {
String method = BSResources.get(paymentAccount.getPaymentMethod().getId());
String address = addressInputTextField.getText();
address = StringUtils.abbreviate(address, 9);
String currency = paymentAccount.getSingleTradeCurrency() != null ? paymentAccount.getSingleTradeCurrency().getCode() : "?";
accountNameTextField.setText(currency.concat(": ").concat(address));
if (currency != null) {
String address = addressInputTextField.getText();
address = StringUtils.abbreviate(address, 9);
accountNameTextField.setText(currency.concat(": ").concat(address));
}
}
}

View file

@ -279,14 +279,18 @@ public class SepaForm extends PaymentMethodForm {
@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) {
String iban = ibanInputTextField.getText();
if (iban.length() > 9)
iban = StringUtils.abbreviate(iban, 9);
String method = BSResources.get(paymentAccount.getPaymentMethod().getId());
CountryBasedPaymentAccount countryBasedPaymentAccount = (CountryBasedPaymentAccount) this.paymentAccount;
String country = countryBasedPaymentAccount.getCountry() != null ? countryBasedPaymentAccount.getCountry().code : "?";
String currency = this.paymentAccount.getSingleTradeCurrency() != null ? this.paymentAccount.getSingleTradeCurrency().getCode() : "?";
accountNameTextField.setText(method.concat(" (").concat(currency).concat("/").concat(country).concat("): ").concat(iban));
TradeCurrency singleTradeCurrency = this.paymentAccount.getSingleTradeCurrency();
String currency = singleTradeCurrency != null ? singleTradeCurrency.getCode() : null;
if (currency != null) {
String iban = ibanInputTextField.getText();
if (iban.length() > 9)
iban = StringUtils.abbreviate(iban, 9);
String method = BSResources.get(paymentAccount.getPaymentMethod().getId());
CountryBasedPaymentAccount countryBasedPaymentAccount = (CountryBasedPaymentAccount) this.paymentAccount;
String country = countryBasedPaymentAccount.getCountry() != null ? countryBasedPaymentAccount.getCountry().code : null;
if (country != null)
accountNameTextField.setText(method.concat(" (").concat(currency).concat("/").concat(country).concat("): ").concat(iban));
}
}
}

View file

@ -86,7 +86,10 @@ public class P2pNetworkListItem {
}
private void onLastActivityChanged(long timeStamp) {
lastActivity.set(DurationFormatUtils.formatDuration(System.currentTimeMillis() - timeStamp, "mm:ss.SSS"));
// TODO
// Got one case where System.currentTimeMillis() - timeStamp resulted in a negative value,
// probably caused by a threading issue. Protect it with Math.abs for a quick fix...
lastActivity.set(DurationFormatUtils.formatDuration(Math.abs(System.currentTimeMillis() - timeStamp), "mm:ss.SSS"));
}
public void cleanup() {