From 5c5b2969d76326ffc7a6ef9af0c2e9fedd493170 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Tue, 13 Jun 2023 09:04:00 +0200 Subject: [PATCH] Wallet: extract local variables `tempParentFile` and `destParentFile` in method `saveToFile()` This is meant to make it a bit clearer why a NullPointerException would occur. --- core/src/main/java/org/bitcoinj/wallet/Wallet.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/wallet/Wallet.java b/core/src/main/java/org/bitcoinj/wallet/Wallet.java index a22979ab6..79b8085a8 100644 --- a/core/src/main/java/org/bitcoinj/wallet/Wallet.java +++ b/core/src/main/java/org/bitcoinj/wallet/Wallet.java @@ -1692,11 +1692,13 @@ public class Wallet extends BaseTaggableObject * @throws IOException if an error occurs while saving */ public void saveToFile(File tempFile, File destFile) throws IOException { - if (!tempFile.getParentFile().exists()) { - throw new FileNotFoundException(tempFile.getParentFile().getPath() + " (wallet directory not found)"); + File tempParentFile = tempFile.getParentFile(); + if (!tempParentFile.exists()) { + throw new FileNotFoundException(tempParentFile.getPath() + " (wallet directory not found)"); } - if (!destFile.getParentFile().exists()) { - throw new FileNotFoundException(destFile.getParentFile().getPath() + " (wallet directory not found)"); + File destParentFile = destFile.getParentFile(); + if (!destParentFile.exists()) { + throw new FileNotFoundException(destParentFile.getPath() + " (wallet directory not found)"); } FileOutputStream stream = null; lock.lock();