mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-30 23:02:15 +00:00
Clear all possible NPE findbugs warnings, and fix some getter/setter synchronization mismatches.
This commit is contained in:
parent
002539f2b8
commit
85c9950d9e
@ -131,15 +131,18 @@ public class MemoryPool {
|
||||
// We've seen at least one peer announce with an inv.
|
||||
Preconditions.checkNotNull(entry.addresses);
|
||||
return entry.addresses.size();
|
||||
} else if (entry.tx.get() == null) {
|
||||
// We previously downloaded this transaction, but nothing cared about it so the garbage collector threw
|
||||
// it away. We also deleted the set that tracked which peers had seen it. Treat this case as a zero and
|
||||
// just delete it from the map.
|
||||
memoryPool.remove(txHash);
|
||||
return 0;
|
||||
} else {
|
||||
Preconditions.checkState(entry.addresses == null);
|
||||
return entry.tx.get().getConfidence().numBroadcastPeers();
|
||||
final Transaction tx = entry.tx.get();
|
||||
if (tx == null) {
|
||||
// We previously downloaded this transaction, but nothing cared about it so the garbage collector threw
|
||||
// it away. We also deleted the set that tracked which peers had seen it. Treat this case as a zero and
|
||||
// just delete it from the map.
|
||||
memoryPool.remove(txHash);
|
||||
return 0;
|
||||
} else {
|
||||
Preconditions.checkState(entry.addresses == null);
|
||||
return tx.getConfidence().numBroadcastPeers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ public class MemoryFullPrunedBlockStore implements FullPrunedBlockStore {
|
||||
return storedBlock == null ? null : storedBlock.block;
|
||||
}
|
||||
|
||||
public StoredBlock getOnceUndoableStoredBlock(Sha256Hash hash) throws BlockStoreException {
|
||||
public synchronized StoredBlock getOnceUndoableStoredBlock(Sha256Hash hash) throws BlockStoreException {
|
||||
Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed");
|
||||
StoredBlockAndWasUndoableFlag storedBlock = blockMap.get(hash);
|
||||
return (storedBlock != null && storedBlock.wasUndoable) ? storedBlock.block : null;
|
||||
@ -377,7 +377,7 @@ public class MemoryFullPrunedBlockStore implements FullPrunedBlockStore {
|
||||
return fullBlockMap.get(hash);
|
||||
}
|
||||
|
||||
public StoredBlock getChainHead() throws BlockStoreException {
|
||||
public synchronized StoredBlock getChainHead() throws BlockStoreException {
|
||||
Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed");
|
||||
return chainHead;
|
||||
}
|
||||
@ -387,12 +387,12 @@ public class MemoryFullPrunedBlockStore implements FullPrunedBlockStore {
|
||||
this.chainHead = chainHead;
|
||||
}
|
||||
|
||||
public StoredBlock getVerifiedChainHead() throws BlockStoreException {
|
||||
public synchronized StoredBlock getVerifiedChainHead() throws BlockStoreException {
|
||||
Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed");
|
||||
return verifiedChainHead;
|
||||
}
|
||||
|
||||
public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException {
|
||||
public synchronized void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException {
|
||||
Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed");
|
||||
this.verifiedChainHead = chainHead;
|
||||
if (this.chainHead.getHeight() < chainHead.getHeight())
|
||||
@ -442,7 +442,7 @@ public class MemoryFullPrunedBlockStore implements FullPrunedBlockStore {
|
||||
transactionOutputMap.abortDatabaseBatchWrite();
|
||||
}
|
||||
|
||||
public boolean hasUnspentOutputs(Sha256Hash hash, int numOutputs) throws BlockStoreException {
|
||||
public synchronized boolean hasUnspentOutputs(Sha256Hash hash, int numOutputs) throws BlockStoreException {
|
||||
for (int i = 0; i < numOutputs; i++)
|
||||
if (getTransactionOutput(hash, i) != null)
|
||||
return true;
|
||||
|
@ -122,10 +122,13 @@ public class FullPrunedBlockChainTest {
|
||||
|
||||
chain.add(rollingBlock);
|
||||
WeakReference<StoredUndoableBlock> undoBlock = new WeakReference<StoredUndoableBlock>(store.getUndoBlock(rollingBlock.getHash()));
|
||||
assertTrue(undoBlock.get() != null);
|
||||
assertTrue(undoBlock.get().getTransactions() == null);
|
||||
WeakReference<TransactionOutputChanges> changes = new WeakReference<TransactionOutputChanges>(undoBlock.get().getTxOutChanges());
|
||||
|
||||
StoredUndoableBlock storedUndoableBlock = undoBlock.get();
|
||||
assertTrue(storedUndoableBlock != null);
|
||||
assertTrue(storedUndoableBlock.getTransactions() == null);
|
||||
WeakReference<TransactionOutputChanges> changes = new WeakReference<TransactionOutputChanges>(storedUndoableBlock.getTxOutChanges());
|
||||
assertTrue(changes.get() != null);
|
||||
storedUndoableBlock = null; // Blank the reference so it can be GCd.
|
||||
|
||||
// Create a chain longer than UNDOABLE_BLOCKS_STORED
|
||||
for (int i = 0; i < UNDOABLE_BLOCKS_STORED; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user