From 37f70b52377b8ed380559a48041a77d7e9205454 Mon Sep 17 00:00:00 2001 From: Max Gaukler Date: Tue, 26 Dec 2023 13:04:02 +0100 Subject: [PATCH] Fix NullPointerException when settings directory does not yet exist --- .../thomas_oster/visicut/managers/PreferencesManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/thomas_oster/visicut/managers/PreferencesManager.java b/src/main/java/de/thomas_oster/visicut/managers/PreferencesManager.java index 1af7cf31..d428cfec 100644 --- a/src/main/java/de/thomas_oster/visicut/managers/PreferencesManager.java +++ b/src/main/java/de/thomas_oster/visicut/managers/PreferencesManager.java @@ -333,6 +333,10 @@ public void savePreferences(Preferences pref) throws FileNotFoundException, IOEx public void savePreferences() throws FileNotFoundException, IOException { + if (preferences == null) + { + preferences = new Preferences(); + } File target = this.getPreferencesPath(); File settingsDir = target.getParentFile(); if (settingsDir.isDirectory() || settingsDir.mkdirs()) @@ -343,7 +347,7 @@ public void savePreferences() throws FileNotFoundException, IOException this.savePreferences(anonymizedPreferences, target); // save full preferences file (settings.private.xml), including sensitive information (e.g., recent files) - // Note that this must be after saving the first file so that the modification date is newer. + // Note that this must be after saving the first file so that the modification date is newer (or same). this.savePreferences(preferences, getPrivatePreferencesPath()); } else