From d36de01be51c03ea3dd271213467a99393f93894 Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sat, 13 Apr 2019 12:46:17 -0700 Subject: [PATCH] = Corrected edge case of null string parsing --- localization.config | 2 -- src/commands/CommandShutdown.java | 9 ++++++--- src/core/Localizer.java | 7 +++---- src/dataStructures/SectionedKeyValueStore.java | 3 +++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/localization.config b/localization.config index 8970ef7..9b38c19 100644 --- a/localization.config +++ b/localization.config @@ -58,8 +58,6 @@ You successfully voted for= [CommandShutdown] Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown.= -Forced shutdown, database synced before abandoning threads.= -Forced immediate shutdown, threads abandoned without sync.= [CommandBetBeans] That's not a valid bet!= diff --git a/src/commands/CommandShutdown.java b/src/commands/CommandShutdown.java index 0963d7a..2d6cdd7 100644 --- a/src/commands/CommandShutdown.java +++ b/src/commands/CommandShutdown.java @@ -11,6 +11,8 @@ import dataStructures.KittyRole; import dataStructures.KittyUser; import dataStructures.Response; import dataStructures.UserInput; +import utils.GlobalLog; +import utils.LogFilter; // NOTE(wisp): This is a sort of special command. public class CommandShutdown extends Command @@ -41,13 +43,14 @@ public class CommandShutdown extends Command if(isSafe) { - DatabaseManager.instance.Upkeep(); // Force upkeep, this works so long as on main thread. - res.CallImmediate(Localizer.Stub("Forced shutdown, database synced before abandoning threads.")); + // Force upkeep, this works so long as upkeep is on the main thread. + DatabaseManager.instance.Upkeep(); + GlobalLog.Error(LogFilter.Command, "Forced shutdown, database synced before abandoning threads."); System.exit(0); } else { - res.CallImmediate(Localizer.Stub("Forced immediate shutdown, threads abandoned without sync.")); + GlobalLog.Error(LogFilter.Command, "Forced immediate shutdown, threads abandoned without sync."); System.exit(0); } } diff --git a/src/core/Localizer.java b/src/core/Localizer.java index beb86a0..9487b2e 100644 --- a/src/core/Localizer.java +++ b/src/core/Localizer.java @@ -123,16 +123,15 @@ public class Localizer try { String fileContents = ReadFileAsString(filename, Charset.defaultCharset()); + System.out.println("File contents: " + fileContents); if(fileContents == null) { File file = new File(filename); file.createNewFile(); } - else - { - stringStore = new SectionedKeyValueStore(fileContents); - } + + stringStore = new SectionedKeyValueStore(fileContents); } catch(IOException e) { diff --git a/src/dataStructures/SectionedKeyValueStore.java b/src/dataStructures/SectionedKeyValueStore.java index 0f67458..058ed3c 100644 --- a/src/dataStructures/SectionedKeyValueStore.java +++ b/src/dataStructures/SectionedKeyValueStore.java @@ -109,6 +109,9 @@ public class SectionedKeyValueStore // account of some characters having specific regex meanings. private void Parse(String input) { + if(input == null) + return; + String[] sections = input.split("\\" + SectionStart); for(int sec = 0; sec < sections.length; ++sec)