From 64f47b01fb0c35ce9b30b7c7d08ff2e32b149a76 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Fri, 13 Jan 2012 05:47:14 -0600 Subject: [PATCH] Errors loading conf.json are handled better now, allowing Factions to continue loading the board instead of losing it Also, the bad conf.json file is backed up to conf.json_bad so it can potentially be recovered --- .../factions/zcore/util/Persist.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/com/massivecraft/factions/zcore/util/Persist.java b/src/com/massivecraft/factions/zcore/util/Persist.java index 89c6aafd..bfa51b8c 100644 --- a/src/com/massivecraft/factions/zcore/util/Persist.java +++ b/src/com/massivecraft/factions/zcore/util/Persist.java @@ -86,6 +86,13 @@ public class Persist { if (loaded == null) { p.log(Level.WARNING, "Using default as I failed to load: "+file); + + // backup bad file, so user can attempt to recover their changes from it + File backup = new File(file.getPath()+"_bad"); + if (backup.exists()) backup.delete(); + p.log(Level.WARNING, "Backing up copy of bad file to: "+backup); + file.renameTo(backup); + return def; } @@ -128,10 +135,18 @@ public class Persist { { return null; } - - T instance = p.gson.fromJson(content, clazz); - - return instance; + + try + { + T instance = p.gson.fromJson(content, clazz); + return instance; + } + catch (Exception ex) + { // output the error message rather than full stack trace; error parsing the file, most likely + p.log(Level.WARNING, ex.getMessage()); + } + + return null; }