Skip to content

Commit

Permalink
Constructors should only call non-overridable methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-vlasov authored and schildbach committed Jan 6, 2016
1 parent 61ae489 commit e3e8e80
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/org/bitcoinj/core/AbstractBlockChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public AbstractBlockChain(Context context, List<? extends Wallet> wallets,
* have never been in use, or if the wallet has been loaded along with the BlockChain. Note that adding multiple
* wallets is not well tested!
*/
public void addWallet(Wallet wallet) {
public final void addWallet(Wallet wallet) {
addNewBestBlockListener(Threading.SAME_THREAD, wallet);
addReorganizeListener(Threading.SAME_THREAD, wallet);
addTransactionReceivedListener(Threading.SAME_THREAD, wallet);
Expand Down Expand Up @@ -231,7 +231,7 @@ public void addNewBestBlockListener(NewBestBlockListener listener) {
/**
* Adds a {@link NewBestBlockListener} listener to the chain.
*/
public void addNewBestBlockListener(Executor executor, NewBestBlockListener listener) {
public final void addNewBestBlockListener(Executor executor, NewBestBlockListener listener) {
newBestBlockListeners.add(new ListenerRegistration<NewBestBlockListener>(listener, executor));
}

Expand All @@ -245,7 +245,7 @@ public void addReorganizeListener(ReorganizeListener listener) {
/**
* Adds a generic {@link ReorganizeListener} listener to the chain.
*/
public void addReorganizeListener(Executor executor, ReorganizeListener listener) {
public final void addReorganizeListener(Executor executor, ReorganizeListener listener) {
reorganizeListeners.add(new ListenerRegistration<ReorganizeListener>(listener, executor));
}

Expand All @@ -259,7 +259,7 @@ public void addTransactionReceivedListener(TransactionReceivedInBlockListener li
/**
* Adds a generic {@link TransactionReceivedInBlockListener} listener to the chain.
*/
public void addTransactionReceivedListener(Executor executor, TransactionReceivedInBlockListener listener) {
public final void addTransactionReceivedListener(Executor executor, TransactionReceivedInBlockListener listener) {
transactionReceivedListeners.add(new ListenerRegistration<TransactionReceivedInBlockListener>(listener, executor));
}

Expand Down Expand Up @@ -860,7 +860,7 @@ private static StoredBlock findSplit(StoredBlock newChainHead, StoredBlock oldCh
/**
* @return the height of the best known chain, convenience for <tt>getChainHead().getHeight()</tt>.
*/
public int getBestChainHeight() {
public final int getBestChainHeight() {
return getChainHead().getHeight();
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/core/ChildMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ChildMessage(NetworkParameters params, byte[] payload, int offset, @Nulla
this.parent = parent;
}

public void setParent(@Nullable Message parent) {
public final 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
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/core/VarInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public int getOriginalSizeInBytes() {
/**
* Returns the minimum encoded size of the value.
*/
public int getSizeInBytes() {
public final int getSizeInBytes() {
return sizeOf(value);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public DeterministicKeyChain getActiveKeyChain() {
* <p>Transaction signer should be fully initialized before adding to the wallet, otherwise {@link IllegalStateException}
* will be thrown</p>
*/
public void addTransactionSigner(TransactionSigner signer) {
public final void addTransactionSigner(TransactionSigner signer) {
lock.lock();
try {
if (signer.isReady())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DeterministicHierarchy(DeterministicKey rootKey) {
* Inserts a key into the heirarchy. Used during deserialization: you normally don't need this. Keys must be
* inserted in order.
*/
public void putKey(DeterministicKey key) {
public final void putKey(DeterministicKey key) {
ImmutableList<ChildNumber> path = key.getPath();
// Update our tracking of what the next child in each branch of the tree should be. Just assume that keys are
// inserted in order here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class AbstractTimeoutHandler {
*
* <p>This call will reset the current progress towards the timeout.</p>
*/
public synchronized void setTimeoutEnabled(boolean timeoutEnabled) {
public synchronized final void setTimeoutEnabled(boolean timeoutEnabled) {
this.timeoutEnabled = timeoutEnabled;
resetTimeout();
}
Expand All @@ -56,7 +56,7 @@ public synchronized void setTimeoutEnabled(boolean timeoutEnabled) {
*
* <p>This call will reset the current progress towards the timeout.</p>
*/
public synchronized void setSocketTimeout(int timeoutMillis) {
public synchronized final void setSocketTimeout(int timeoutMillis) {
this.timeoutMillis = timeoutMillis;
resetTimeout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public StoredPaymentChannelClientStates(@Nullable Wallet containingWallet) {
*
* @param transactionBroadcaster which is used to complete and announce contract and refund transactions.
*/
public void setTransactionBroadcaster(TransactionBroadcaster transactionBroadcaster) {
public final void setTransactionBroadcaster(TransactionBroadcaster transactionBroadcaster) {
this.announcePeerGroupFuture.set(checkNotNull(transactionBroadcaster));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public StoredPaymentChannelServerStates(@Nullable Wallet wallet) {
*
* @param broadcaster Used when the payment channels are closed
*/
public void setTransactionBroadcaster(TransactionBroadcaster broadcaster) {
public final void setTransactionBroadcaster(TransactionBroadcaster broadcaster) {
this.broadcasterFuture.set(checkNotNull(broadcaster));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ protected String getSelectopenoutputsDumpSQL() {
* <p>This will also automatically set up the schema if it does not exist within the DB.</p>
* @throws BlockStoreException if successful connection to the DB couldn't be made.
*/
protected synchronized void maybeConnect() throws BlockStoreException {
protected synchronized final void maybeConnect() throws BlockStoreException {
try {
if (conn.get() != null && !conn.get().isClosed())
return;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/store/MemoryBlockStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public MemoryBlockStore(NetworkParameters params) {
}

@Override
public synchronized void put(StoredBlock block) throws BlockStoreException {
public synchronized final void put(StoredBlock block) throws BlockStoreException {
if (blockMap == null) throw new BlockStoreException("MemoryBlockStore is closed");
Sha256Hash hash = block.getHeader().getHash();
blockMap.put(hash, block);
Expand All @@ -69,7 +69,7 @@ public StoredBlock getChainHead() throws BlockStoreException {
}

@Override
public void setChainHead(StoredBlock chainHead) throws BlockStoreException {
public final void setChainHead(StoredBlock chainHead) throws BlockStoreException {
if (blockMap == null) throw new BlockStoreException("MemoryBlockStore is closed");
this.chainHead = chainHead;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public synchronized void put(StoredBlock block) throws BlockStoreException {
}

@Override
public synchronized void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException {
public synchronized final void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException {
Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed");
Sha256Hash hash = storedBlock.getHeader().getHash();
fullBlockMap.put(hash, storedBlock.getHeight(), undoableBlock);
Expand Down Expand Up @@ -319,7 +319,7 @@ public synchronized StoredBlock getChainHead() throws BlockStoreException {
}

@Override
public synchronized void setChainHead(StoredBlock chainHead) throws BlockStoreException {
public synchronized final void setChainHead(StoredBlock chainHead) throws BlockStoreException {
Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed");
this.chainHead = chainHead;
}
Expand All @@ -331,7 +331,7 @@ public synchronized StoredBlock getVerifiedChainHead() throws BlockStoreExceptio
}

@Override
public synchronized void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException {
public synchronized final void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException {
Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed");
this.verifiedChainHead = chainHead;
if (this.chainHead.getHeight() < chainHead.getHeight())
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/store/SPVBlockStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void initNewStore(NetworkParameters params) throws Exception {
}

/** Returns the size in bytes of the file that is used to store the chain with the current parameters. */
public int getFileSize() {
public final int getFileSize() {
return RECORD_SIZE * numHeaders + FILE_PROLOGUE_BYTES /* extra kilobyte for stuff */;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/uri/BitcoinURI.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public String getMessage() {
* @return The URL where a payment request (as specified in BIP 70) may
* be fetched.
*/
public String getPaymentRequestUrl() {
public final String getPaymentRequestUrl() {
return (String) parameterMap.get(FIELD_PAYMENT_REQUEST_URL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ExponentialBackoff(Params params) {
}

/** Track a success - reset back off interval to the initial value */
public void trackSuccess() {
public final void trackSuccess() {
backoff = params.initial;
retryTime = Utils.currentTimeMillis();
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/wallet/KeyChainGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public Address freshAddress(KeyChain.KeyPurpose purpose) {
}

/** Returns the key chain that's used for generation of fresh/current keys. This is always the newest HD chain. */
public DeterministicKeyChain getActiveKeyChain() {
public final DeterministicKeyChain getActiveKeyChain() {
if (chains.isEmpty()) {
if (basic.numKeys() > 0) {
log.warn("No HD chain present but random keys are: you probably deserialized an old wallet.");
Expand Down Expand Up @@ -484,7 +484,7 @@ public boolean removeImportedKey(ECKey key) {
* from multiple keychains in a multisig relationship.
* @see org.bitcoinj.wallet.MarriedKeyChain
*/
public boolean isMarried() {
public final boolean isMarried() {
return !chains.isEmpty() && getActiveKeyChain().isMarried();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void initialize() {
checkNotNull(keyCrypter); // We should never arrive at this GUI if the wallet isn't actually encrypted.
KeyDerivationTasks tasks = new KeyDerivationTasks(keyCrypter, password, getTargetTime()) {
@Override
protected void onFinish(KeyParameter aesKey, int timeTakenMsec) {
protected final void onFinish(KeyParameter aesKey, int timeTakenMsec) {
checkGuiThread();
if (Main.bitcoin.wallet().checkAESKey(aesKey)) {
WalletPasswordController.this.aesKey.set(aesKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void setPasswordClicked(ActionEvent event) {
// Deriving the actual key runs on a background thread. 500msec is empirical on my laptop (actual val is more like 333 but we give padding time).
KeyDerivationTasks tasks = new KeyDerivationTasks(scrypt, password, estimatedKeyDerivationTime) {
@Override
protected void onFinish(KeyParameter aesKey, int timeTakenMsec) {
protected final void onFinish(KeyParameter aesKey, int timeTakenMsec) {
// Write the target time to the wallet so we can make the progress bar work when entering the password.
WalletPasswordController.setTargetTime(Duration.ofMillis(timeTakenMsec));
// The actual encryption part doesn't take very long as most private keys are derived on demand.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public BitcoinUIModel(Wallet wallet) {
setWallet(wallet);
}

public void setWallet(Wallet wallet) {
public final void setWallet(Wallet wallet) {
wallet.addEventListener(new AbstractWalletEventListener() {
@Override
public void onWalletChanged(Wallet wallet) {
Expand Down

0 comments on commit e3e8e80

Please sign in to comment.