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

Throw BlockStoreException not NullPointerException when chain head cannot be found in SPVBlockStore. Resolves issue 374.

This commit is contained in:
Mike Hearn 2013-03-27 17:57:00 +01:00
parent 3c6f435fde
commit 4f1c7f4816

View File

@ -239,7 +239,10 @@ public class SPVBlockStore implements BlockStore {
buffer.position(8); buffer.position(8);
buffer.get(headHash); buffer.get(headHash);
Sha256Hash hash = new Sha256Hash(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; return lastChainHead;
} finally { lock.unlock(); } } 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). */ /** Returns the offset from the file start where the latest block should be written (end of prev block). */
private int getRingCursor(ByteBuffer buffer) { private int getRingCursor(ByteBuffer buffer) {
int c = buffer.getInt(4); int c = buffer.getInt(4);
Preconditions.checkState(c >= FILE_PROLOGUE_BYTES, "Integer overflow"); checkState(c >= FILE_PROLOGUE_BYTES, "Integer overflow");
return c; return c;
} }