From d3eab06dba640d13f4124fa0540ca8a9ebc4b767 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Thu, 11 Jul 2013 16:52:50 +0200 Subject: [PATCH] Make BitcoinURIParseException checked so you can't forget it, and catch/rethrow ArithmeticErrors when parsing the value field. Add more nullity annotations. --- .../java/com/google/bitcoin/core/Address.java | 4 +- .../com/google/bitcoin/uri/BitcoinURI.java | 40 ++++++++++--------- .../bitcoin/uri/BitcoinURIParseException.java | 22 ++++++++-- .../google/bitcoin/uri/BitcoinURITest.java | 23 ++--------- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Address.java b/core/src/main/java/com/google/bitcoin/core/Address.java index 279a8e06..c5ba554a 100644 --- a/core/src/main/java/com/google/bitcoin/core/Address.java +++ b/core/src/main/java/com/google/bitcoin/core/Address.java @@ -19,6 +19,8 @@ package com.google.bitcoin.core; import com.google.bitcoin.params.MainNetParams; import com.google.bitcoin.params.TestNet3Params; +import javax.annotation.Nullable; + /** *

A Bitcoin address looks like 1MsScoe2fTJoq4ZPdQgqyhgWeoNamYPevy and is derived from an elliptic curve public key * plus a set of network parameters. Not to be confused with a {@link PeerAddress} or {@link AddressMessage} @@ -57,7 +59,7 @@ public class Address extends VersionedChecksummedBytes { * @throws AddressFormatException if the given address doesn't parse or the checksum is invalid * @throws WrongNetworkException if the given address is valid but for a different chain (eg testnet vs prodnet) */ - public Address(NetworkParameters params, String address) throws AddressFormatException, WrongNetworkException { + public Address(@Nullable NetworkParameters params, String address) throws AddressFormatException, WrongNetworkException { super(address); if (params != null) { boolean found = false; diff --git a/core/src/main/java/com/google/bitcoin/uri/BitcoinURI.java b/core/src/main/java/com/google/bitcoin/uri/BitcoinURI.java index 9ad3eadf..0dd56d48 100644 --- a/core/src/main/java/com/google/bitcoin/uri/BitcoinURI.java +++ b/core/src/main/java/com/google/bitcoin/uri/BitcoinURI.java @@ -22,10 +22,10 @@ import com.google.bitcoin.core.Address; import com.google.bitcoin.core.AddressFormatException; import com.google.bitcoin.core.NetworkParameters; import com.google.bitcoin.core.Utils; -import com.google.common.base.Preconditions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.net.URI; @@ -34,9 +34,10 @@ import java.net.URLDecoder; import java.util.LinkedHashMap; import java.util.Map; +import static com.google.common.base.Preconditions.checkNotNull; + /** - *

Provides a standard implementation of a Bitcoin URI with support for the - * following:

+ *

Provides a standard implementation of a Bitcoin URI with support for the following:

* *