Skip to content

Commit

Permalink
Tighten scope of the FileInputStream in WalletAppKit to avoid lock co…
Browse files Browse the repository at this point in the history
…llisions on Windows. Resolves issue 556.
  • Loading branch information
mikehearn committed May 13, 2014
1 parent 408bca3 commit acebe8e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions core/src/main/java/com/google/bitcoin/kits/WalletAppKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ protected void startUp() throws Exception {
throw new IOException("Could not create named directory.");
}
}
FileInputStream walletStream = null;
try {
File chainFile = new File(directory, filePrefix + ".spvchain");
boolean chainFileExists = chainFile.exists();
Expand All @@ -216,12 +215,16 @@ protected void startUp() throws Exception {
if (this.userAgent != null)
vPeerGroup.setUserAgent(userAgent, version);
if (vWalletFile.exists()) {
walletStream = new FileInputStream(vWalletFile);
vWallet = new Wallet(params);
addWalletExtensions(); // All extensions must be present before we deserialize
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(walletStream), vWallet);
if (shouldReplayWallet)
vWallet.clearTransactions(0);
FileInputStream walletStream = new FileInputStream(vWalletFile);
try {
vWallet = new Wallet(params);
addWalletExtensions(); // All extensions must be present before we deserialize
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(walletStream), vWallet);
if (shouldReplayWallet)
vWallet.clearTransactions(0);
} finally {
walletStream.close();
}
} else {
vWallet = new Wallet(params);
vWallet.addKey(new ECKey());
Expand Down Expand Up @@ -270,8 +273,6 @@ public void failed(State from, Throwable failure) {
}
} catch (BlockStoreException e) {
throw new IOException(e);
} finally {
if (walletStream != null) walletStream.close();
}
}

Expand Down

0 comments on commit acebe8e

Please sign in to comment.