From d5b4c36fae09b5e72422f17582d72b4623f5cf36 Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Sat, 1 Sep 2018 10:58:18 +0530 Subject: [PATCH] Exception handling improvements to SettingsLoader --- .../everest/controllers/auth/AuthTabController.java | 5 +++++ .../rohitawate/everest/settings/SettingsLoader.java | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rohitawate/everest/controllers/auth/AuthTabController.java b/src/main/java/com/rohitawate/everest/controllers/auth/AuthTabController.java index 7009138..1ddc4e9 100644 --- a/src/main/java/com/rohitawate/everest/controllers/auth/AuthTabController.java +++ b/src/main/java/com/rohitawate/everest/controllers/auth/AuthTabController.java @@ -92,6 +92,11 @@ public class AuthTabController implements Initializable { basicController.setState(state.basicUsername, state.basicPassword, state.basicEnabled); digestController.setState(state.digestUsername, state.digestPassword, state.digestEnabled); + if (state.authMethod == null) { + authTabPane.getSelectionModel().select(0); + return; + } + switch (state.authMethod) { case DataManager.BASIC: authTabPane.getSelectionModel().select(0); diff --git a/src/main/java/com/rohitawate/everest/settings/SettingsLoader.java b/src/main/java/com/rohitawate/everest/settings/SettingsLoader.java index 329024d..acc0f24 100644 --- a/src/main/java/com/rohitawate/everest/settings/SettingsLoader.java +++ b/src/main/java/com/rohitawate/everest/settings/SettingsLoader.java @@ -42,7 +42,11 @@ public class SettingsLoader implements Runnable { File settingsFile = new File("Everest/config/settings.json"); if (settingsFile.exists()) - System.out.println("Settings file found. Loading settings... "); + LoggingService.logInfo("Settings file found. Loading settings.", LocalDateTime.now()); + else { + LoggingService.logInfo("Settings file not found. Loading defaults.", LocalDateTime.now()); + return; + } nodes = EverestUtilities.jsonMapper.readTree(settingsFile); @@ -60,7 +64,9 @@ public class SettingsLoader implements Runnable { Settings.syntaxTheme = EverestUtilities.trimString(setStringSetting(Settings.syntaxTheme, "syntaxTheme")); Settings.showHistoryRange = setIntegerSetting(Settings.showHistoryRange, "showHistoryRange"); } catch (IOException IOE) { - LoggingService.logInfo("Settings file not found. Using defaults.", LocalDateTime.now()); + LoggingService.logInfo("Settings file contains invalid JSON. Loading defaults.", LocalDateTime.now()); + } catch (NullPointerException NPE) { + LoggingService.logInfo("Settings file empty. Loading defualts", LocalDateTime.now()); } }