null pointer bug fix
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 20 Nov 2016 20:36:25 +0000 (22:36 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 20 Nov 2016 20:36:25 +0000 (22:36 +0200)
src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java

index 4a06d06..8e13042 100755 (executable)
@@ -28,18 +28,15 @@ public class ConfigurationManager {
         final File propertiesFile = getPropertiesFile();
         if (!propertiesFile.exists()) {
             initDefaultConfiguration();
-            saveConfigFile();
         } else
             loadConfigFile(propertiesFile);
     }
 
-    private void loadConfigFile(File propertiesFile) throws FileNotFoundException, com.esotericsoftware.yamlbeans.YamlException {
+    private void loadConfigFile(File propertiesFile) throws IOException {
         YamlReader reader = new YamlReader(new FileReader(propertiesFile));
         configuration = reader.read(Configuration.class);
-        if (configuration == null) {
-            configuration = new Configuration();
-            configuration.fileAssociations = new HashSet<>();
-        }
+        if (configuration == null)
+            initDefaultConfiguration();
     }
 
     private void saveConfigFile() throws IOException {
@@ -53,7 +50,10 @@ public class ConfigurationManager {
         configuration.fileAssociations.add(association);
     }
 
-    private void initDefaultConfiguration() {
+    private void initDefaultConfiguration() throws IOException {
+        configuration = new Configuration();
+        configuration.fileAssociations = new HashSet<>();
+
         configuration.navigationRootPath = System.getProperty("user.home") + "/";
         configuration.directoryOpenCommand = "nautilus -w {file}";
 
@@ -65,5 +65,7 @@ public class ConfigurationManager {
         registerFileAssociation(".*\\.avi$", "vlc {file}");
         registerFileAssociation(".*\\.mp4$", "vlc {file}");
         registerFileAssociation(".*\\.mkv$", "vlc {file}");
+
+        saveConfigFile();
     }
 }