3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 23:32:16 +00:00

WalletProtobufSerializer: Add a couple of NPE checks

This commit is contained in:
Mike Hearn 2013-03-30 17:34:30 +00:00
parent 7307308915
commit 49d26ad773

View File

@ -51,6 +51,8 @@ import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.google.protobuf.TextFormat; import com.google.protobuf.TextFormat;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Serialize and de-serialize a wallet to a byte stream containing a * Serialize and de-serialize a wallet to a byte stream containing a
* <a href="http://code.google.com/apis/protocolbuffers/docs/overview.html">protocol buffer</a>. Protocol buffers are * <a href="http://code.google.com/apis/protocolbuffers/docs/overview.html">protocol buffer</a>. Protocol buffers are
@ -460,8 +462,9 @@ public class WalletProtobufSerializer {
final Protos.TransactionOutput transactionOutput = txProto.getTransactionOutput(i); final Protos.TransactionOutput transactionOutput = txProto.getTransactionOutput(i);
if (transactionOutput.hasSpentByTransactionHash()) { if (transactionOutput.hasSpentByTransactionHash()) {
Transaction spendingTx = txMap.get(transactionOutput.getSpentByTransactionHash()); Transaction spendingTx = txMap.get(transactionOutput.getSpentByTransactionHash());
checkNotNull(spendingTx);
final int spendingIndex = transactionOutput.getSpentByTransactionIndex(); final int spendingIndex = transactionOutput.getSpentByTransactionIndex();
TransactionInput input = spendingTx.getInputs().get(spendingIndex); TransactionInput input = checkNotNull(spendingTx.getInput(spendingIndex));
input.connect(output); input.connect(output);
} }
} }