diff --git a/core/src/main/java/com/google/bitcoin/core/BlockChain.java b/core/src/main/java/com/google/bitcoin/core/BlockChain.java
index 52a840fb..c7175905 100644
--- a/core/src/main/java/com/google/bitcoin/core/BlockChain.java
+++ b/core/src/main/java/com/google/bitcoin/core/BlockChain.java
@@ -88,18 +88,19 @@ public class BlockChain extends AbstractBlockChain {
@Override
protected TransactionOutputChanges connectTransactions(int height, Block block) {
// Don't have to do anything as this is only called if(shouldVerifyTransactions())
- return null;
+ throw new UnsupportedOperationException();
}
@Override
protected TransactionOutputChanges connectTransactions(StoredBlock newBlock) {
// Don't have to do anything as this is only called if(shouldVerifyTransactions())
- return null;
+ throw new UnsupportedOperationException();
}
@Override
protected void disconnectTransactions(StoredBlock block) {
- // Don't have to do anything as this is only called if(shouldVerifyTransactions())
+ // Don't have to do anything as this is only called if(shouldVerifyTransactions())
+ throw new UnsupportedOperationException();
}
@Override
diff --git a/core/src/main/java/com/google/bitcoin/core/ChildMessage.java b/core/src/main/java/com/google/bitcoin/core/ChildMessage.java
index 22749e47..b2b4f161 100644
--- a/core/src/main/java/com/google/bitcoin/core/ChildMessage.java
+++ b/core/src/main/java/com/google/bitcoin/core/ChildMessage.java
@@ -15,6 +15,8 @@
*/
package com.google.bitcoin.core;
+import javax.annotation.Nullable;
+
/**
* Represents a Message type that can be contained within another Message. ChildMessages that have a cached
* backing byte array need to invalidate their parent's caches as well as their own if they are modified.
@@ -24,7 +26,7 @@ package com.google.bitcoin.core;
public abstract class ChildMessage extends Message {
private static final long serialVersionUID = -7657113383624517931L;
- private Message parent;
+ @Nullable private Message parent;
protected ChildMessage() {
}
@@ -47,13 +49,13 @@ public abstract class ChildMessage extends Message {
super(params, msg, offset);
}
- public ChildMessage(NetworkParameters params, byte[] msg, int offset, Message parent, boolean parseLazy, boolean parseRetain, int length)
+ public ChildMessage(NetworkParameters params, byte[] msg, int offset, @Nullable Message parent, boolean parseLazy, boolean parseRetain, int length)
throws ProtocolException {
super(params, msg, offset, parseLazy, parseRetain, length);
this.parent = parent;
}
- public void setParent(Message parent) {
+ public void setParent(@Nullable Message parent) {
if (this.parent != null && this.parent != parent && parent != null) {
// After old parent is unlinked it won't be able to receive notice if this ChildMessage
// changes internally. To be safe we invalidate the parent cache to ensure it rebuilds
diff --git a/core/src/main/java/com/google/bitcoin/core/ECKey.java b/core/src/main/java/com/google/bitcoin/core/ECKey.java
index 03ace6b3..3e4ec749 100644
--- a/core/src/main/java/com/google/bitcoin/core/ECKey.java
+++ b/core/src/main/java/com/google/bitcoin/core/ECKey.java
@@ -161,7 +161,7 @@ public class ECKey implements Serializable {
* is more convenient if you are importing a key from elsewhere. The public key will be automatically derived
* from the private key.
*/
- public ECKey(byte[] privKeyBytes, byte[] pubKey) {
+ public ECKey(@Nullable byte[] privKeyBytes, @Nullable byte[] pubKey) {
this(privKeyBytes == null ? null : new BigInteger(1, privKeyBytes), pubKey);
}
@@ -172,7 +172,7 @@ public class ECKey implements Serializable {
* @param pubKey The keys public key
* @param keyCrypter The KeyCrypter that will be used, with an AES key, to encrypt and decrypt the private key
*/
- public ECKey(EncryptedPrivateKey encryptedPrivateKey, byte[] pubKey, KeyCrypter keyCrypter) {
+ public ECKey(@Nullable EncryptedPrivateKey encryptedPrivateKey, @Nullable byte[] pubKey, KeyCrypter keyCrypter) {
this((byte[])null, pubKey);
this.keyCrypter = Preconditions.checkNotNull(keyCrypter);
@@ -186,13 +186,15 @@ public class ECKey implements Serializable {
* be used for signing.
* @param compressed If set to true and pubKey is null, the derived public key will be in compressed form.
*/
- public ECKey(BigInteger privKey, byte[] pubKey, boolean compressed) {
+ public ECKey(@Nullable BigInteger privKey, @Nullable byte[] pubKey, boolean compressed) {
+ if (privKey == null && pubKey == null)
+ throw new IllegalArgumentException("ECKey requires at least private or public key");
this.priv = privKey;
this.pub = null;
- if (pubKey == null && privKey != null) {
+ if (pubKey == null) {
// Derive public from private.
this.pub = publicKeyFromPrivate(privKey, compressed);
- } else if (pubKey != null) {
+ } else {
// We expect the pubkey to be in regular encoded form, just as a BigInteger. Therefore the first byte is
// a special marker byte.
// TODO: This is probably not a useful API and may be confusing.
@@ -206,7 +208,7 @@ public class ECKey implements Serializable {
* the public key already correctly matches the public key. If only the public key is supplied, this ECKey cannot
* be used for signing.
*/
- private ECKey(BigInteger privKey, byte[] pubKey) {
+ private ECKey(@Nullable BigInteger privKey, @Nullable byte[] pubKey) {
this(privKey, pubKey, false);
}
@@ -381,7 +383,7 @@ public class ECKey implements Serializable {
r = (DERInteger) seq.getObjectAt(0);
s = (DERInteger) seq.getObjectAt(1);
} catch (ClassCastException e) {
- return null;
+ throw new IllegalArgumentException(e);
}
decoder.close();
// OpenSSL deviates from the DER spec by interpreting these values as unsigned, though they should not be
@@ -431,7 +433,7 @@ public class ECKey implements Serializable {
* @param aesKey The AES key to use for decryption of the private key. If null then no decryption is required.
* @throws KeyCrypterException if this ECKey doesn't have a private part.
*/
- public ECDSASignature sign(Sha256Hash input, KeyParameter aesKey) throws KeyCrypterException {
+ public ECDSASignature sign(Sha256Hash input, @Nullable KeyParameter aesKey) throws KeyCrypterException {
if (FAKE_SIGNATURES)
return TransactionSignature.dummy();
@@ -601,7 +603,7 @@ public class ECKey implements Serializable {
* @throws IllegalStateException if this ECKey does not have the private part.
* @throws KeyCrypterException if this ECKey is encrypted and no AESKey is provided or it does not decrypt the ECKey.
*/
- public String signMessage(String message, KeyParameter aesKey) throws KeyCrypterException {
+ public String signMessage(String message, @Nullable KeyParameter aesKey) throws KeyCrypterException {
if (priv == null)
throw new IllegalStateException("This ECKey does not have the private key necessary for signing.");
byte[] data = Utils.formatMessageForSigning(message);
@@ -702,6 +704,7 @@ public class ECKey implements Serializable {
* @param compressed Whether or not the original pubkey was compressed.
* @return An ECKey containing only the public part, or null if recovery wasn't possible.
*/
+ @Nullable
public static ECKey recoverFromSignature(int recId, ECDSASignature sig, Sha256Hash message, boolean compressed) {
Preconditions.checkArgument(recId >= 0, "recId must be positive");
Preconditions.checkArgument(sig.r.compareTo(BigInteger.ZERO) >= 0, "r must be positive");
diff --git a/core/src/main/java/com/google/bitcoin/core/FullPrunedBlockChain.java b/core/src/main/java/com/google/bitcoin/core/FullPrunedBlockChain.java
index 3899010c..d5cd3ee0 100644
--- a/core/src/main/java/com/google/bitcoin/core/FullPrunedBlockChain.java
+++ b/core/src/main/java/com/google/bitcoin/core/FullPrunedBlockChain.java
@@ -22,6 +22,7 @@ import com.google.bitcoin.store.FullPrunedBlockStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.annotation.Nullable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -124,6 +125,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
this.tx = tx; this.prevOutScripts = prevOutScripts; this.enforcePayToScriptHash = enforcePayToScriptHash;
}
+ @Nullable
@Override
public VerificationException call() throws Exception {
try{
diff --git a/core/src/main/java/com/google/bitcoin/core/Message.java b/core/src/main/java/com/google/bitcoin/core/Message.java
index 48b2ed8b..7bb4ee84 100644
--- a/core/src/main/java/com/google/bitcoin/core/Message.java
+++ b/core/src/main/java/com/google/bitcoin/core/Message.java
@@ -380,7 +380,7 @@ public abstract class Message implements Serializable {
* so BitcoinSerializer can avoid 2 instanceof checks + a casting.
*/
public Sha256Hash getHash() {
- return null;
+ throw new UnsupportedOperationException();
}
/**
@@ -388,8 +388,6 @@ public abstract class Message implements Serializable {
* implemented in a subclass of ChildMessage lazy parsing may have no effect.
*
* This default implementation is a safe fall back that will ensure it returns a correct value by parsing the message.
- *
- * @return
*/
public int getMessageSize() {
if (length != UNKNOWN_LENGTH)
diff --git a/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java b/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java
index 8ef1e84a..5b6d3474 100644
--- a/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java
+++ b/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java
@@ -22,6 +22,7 @@ import com.google.bitcoin.script.ScriptOpCodes;
import com.google.common.base.Objects;
import org.spongycastle.util.encoders.Hex;
+import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.math.BigInteger;
@@ -185,6 +186,7 @@ public abstract class NetworkParameters implements Serializable {
}
/** Returns the network parameters for the given string ID or NULL if not recognized. */
+ @Nullable
public static NetworkParameters fromID(String id) {
if (id.equals(ID_MAINNET)) {
return MainNetParams.get();
diff --git a/core/src/main/java/com/google/bitcoin/core/PeerEventListener.java b/core/src/main/java/com/google/bitcoin/core/PeerEventListener.java
index 5caa87b9..0ef15f9c 100644
--- a/core/src/main/java/com/google/bitcoin/core/PeerEventListener.java
+++ b/core/src/main/java/com/google/bitcoin/core/PeerEventListener.java
@@ -16,6 +16,7 @@
package com.google.bitcoin.core;
+import javax.annotation.Nullable;
import java.util.List;
/**
@@ -85,5 +86,6 @@ public interface PeerEventListener {
*
Note that this will never be called if registered with any executor other than
* {@link com.google.bitcoin.utils.Threading#SAME_THREAD}
*/
+ @Nullable
public List getData(Peer peer, GetDataMessage m);
}
diff --git a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
index 4b9b1bde..8384ada2 100644
--- a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
+++ b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
@@ -149,14 +149,6 @@ public class PeerGroup extends AbstractExecutionThreadService implements Transac
private LinkedBlockingQueue