From b58aa9535a92197dfb2235d1951de31b718a7e2b Mon Sep 17 00:00:00 2001
From: yermak <yermak@gmail.com>
Date: Fri, 29 Jan 2021 19:06:49 +0000
Subject: [PATCH] fix #200

---
 .../yermak/audiobookconverter/AppProperties.java  | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/main/java/uk/yermak/audiobookconverter/AppProperties.java b/src/main/java/uk/yermak/audiobookconverter/AppProperties.java
index 0afd2188..6e484a2a 100644
--- a/src/main/java/uk/yermak/audiobookconverter/AppProperties.java
+++ b/src/main/java/uk/yermak/audiobookconverter/AppProperties.java
@@ -15,11 +15,13 @@ public class AppProperties {
     final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
     public static final File APP_DIR = new File(System.getProperty("APP_HOME"));
     public static final File PROP_FILE = new File(APP_DIR, Version.getVersionString() + ".properties");
+    private static final Properties applicationProps = new Properties();
 
-    private static Properties getAppProperties() {
-        //TODO:add default props here
-        Properties defaultProperties = new Properties();
-        Properties applicationProps = new Properties(defaultProperties);
+    static {
+        loadAppProperties();
+    }
+
+    private static synchronized Properties loadAppProperties() {
         if (PROP_FILE.exists()) {
             try (FileInputStream in = new FileInputStream(PROP_FILE)) {
                 applicationProps.load(in);
@@ -31,13 +33,11 @@ public class AppProperties {
     }
 
     public static String getProperty(String key) {
-        Properties applicationProps = getAppProperties();
         return applicationProps.getProperty(key);
     }
 
     public static Properties getProperties(String group) {
         Properties properties = new Properties();
-        Properties applicationProps = getAppProperties();
         Enumeration<Object> keys = applicationProps.keys();
         while (keys.hasMoreElements()) {
             String propName = (String) keys.nextElement();
@@ -49,8 +49,7 @@ public class AppProperties {
         return properties;
     }
 
-    public static void setProperty(String key, String value) {
-        Properties applicationProps = getAppProperties();
+    public static synchronized void setProperty(String key, String value) {
         applicationProps.put(key, value);
         File appDir = APP_DIR;
         if (appDir.exists() || appDir.mkdir()) {
-- 
GitLab