From 4f1c7f4816db91a5555d5174543d256f22947bc9 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 27 Mar 2013 17:57:00 +0100 Subject: [PATCH] Throw BlockStoreException not NullPointerException when chain head cannot be found in SPVBlockStore. Resolves issue 374. --- .../main/java/com/google/bitcoin/store/SPVBlockStore.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/store/SPVBlockStore.java b/core/src/main/java/com/google/bitcoin/store/SPVBlockStore.java index 3703e16b..2882cd0e 100644 --- a/core/src/main/java/com/google/bitcoin/store/SPVBlockStore.java +++ b/core/src/main/java/com/google/bitcoin/store/SPVBlockStore.java @@ -239,7 +239,10 @@ public class SPVBlockStore implements BlockStore { buffer.position(8); buffer.get(headHash); Sha256Hash hash = new Sha256Hash(headHash); - lastChainHead = checkNotNull(get(hash), "Corrupted block store: could not find chain head: " + hash); + StoredBlock block = get(hash); + if (block == null) + throw new BlockStoreException("Corrupted block store: could not find chain head: " + hash); + lastChainHead = block; } return lastChainHead; } finally { lock.unlock(); } @@ -285,7 +288,7 @@ public class SPVBlockStore implements BlockStore { /** Returns the offset from the file start where the latest block should be written (end of prev block). */ private int getRingCursor(ByteBuffer buffer) { int c = buffer.getInt(4); - Preconditions.checkState(c >= FILE_PROLOGUE_BYTES, "Integer overflow"); + checkState(c >= FILE_PROLOGUE_BYTES, "Integer overflow"); return c; }