Wallet: extract local variables tempParentFile and destParentFile in method saveToFile()

This is meant to make it a bit clearer why a NullPointerException would occur.
This commit is contained in:
Andreas Schildbach 2023-06-13 09:04:00 +02:00
parent 87a2892bca
commit 5c5b2969d7

View file

@ -1692,11 +1692,13 @@ public class Wallet extends BaseTaggableObject
* @throws IOException if an error occurs while saving * @throws IOException if an error occurs while saving
*/ */
public void saveToFile(File tempFile, File destFile) throws IOException { public void saveToFile(File tempFile, File destFile) throws IOException {
if (!tempFile.getParentFile().exists()) { File tempParentFile = tempFile.getParentFile();
throw new FileNotFoundException(tempFile.getParentFile().getPath() + " (wallet directory not found)"); if (!tempParentFile.exists()) {
throw new FileNotFoundException(tempParentFile.getPath() + " (wallet directory not found)");
} }
if (!destFile.getParentFile().exists()) { File destParentFile = destFile.getParentFile();
throw new FileNotFoundException(destFile.getParentFile().getPath() + " (wallet directory not found)"); if (!destParentFile.exists()) {
throw new FileNotFoundException(destParentFile.getPath() + " (wallet directory not found)");
} }
FileOutputStream stream = null; FileOutputStream stream = null;
lock.lock(); lock.lock();