From d8564a050fc7574ab8a25bc3a21c1632f13efd9f Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 18 Apr 2013 02:08:41 -0500 Subject: [PATCH] Additional Exception catching for errors which might occur when loading JSON files --- .../factions/zcore/persist/EntityCollection.java | 3 +-- .../massivecraft/factions/zcore/util/Persist.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/com/massivecraft/factions/zcore/persist/EntityCollection.java b/src/com/massivecraft/factions/zcore/persist/EntityCollection.java index 265118e0..b19fcca1 100644 --- a/src/com/massivecraft/factions/zcore/persist/EntityCollection.java +++ b/src/com/massivecraft/factions/zcore/persist/EntityCollection.java @@ -8,7 +8,6 @@ import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.com.google.gson.Gson; -import org.bukkit.craftbukkit.libs.com.google.gson.JsonSyntaxException; import com.massivecraft.factions.zcore.util.DiscUtil; import com.massivecraft.factions.zcore.util.TextUtil; @@ -223,7 +222,7 @@ public abstract class EntityCollection { return this.gson.fromJson(content, type); } - catch(JsonSyntaxException ex) + catch(Exception ex) { Bukkit.getLogger().log(Level.WARNING, "JSON error encountered loading \"" + file + "\": " + ex.getLocalizedMessage()); diff --git a/src/com/massivecraft/factions/zcore/util/Persist.java b/src/com/massivecraft/factions/zcore/util/Persist.java index bfa51b8c..56ba920d 100644 --- a/src/com/massivecraft/factions/zcore/util/Persist.java +++ b/src/com/massivecraft/factions/zcore/util/Persist.java @@ -164,8 +164,16 @@ public class Persist { if (content == null) { return null; } - - return (T) p.gson.fromJson(content, typeOfT); + + try + { + return (T) p.gson.fromJson(content, typeOfT); + } + 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; } - }