From ebde7bcc1ac4e9e68da969efd3bf19c00b862d66 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Mon, 28 Mar 2011 14:38:07 -0500 Subject: [PATCH] attempt to handle an NPE someone has been getting in MyLocationTypeAdapter.serialize() --- src/com/bukkit/mcteam/factions/Faction.java | 6 +++++- .../mcteam/factions/MyLocationTypeAdapter.java | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/com/bukkit/mcteam/factions/Faction.java b/src/com/bukkit/mcteam/factions/Faction.java index d926a60d..ae0c4f54 100644 --- a/src/com/bukkit/mcteam/factions/Faction.java +++ b/src/com/bukkit/mcteam/factions/Faction.java @@ -332,7 +332,11 @@ public class Faction { try { DiscUtil.write(file, Factions.gson.toJson(instances)); } catch (IOException e) { - Factions.log("Failed to save the factions to disk."); + Factions.log("Failed to save the factions to disk due to I/O exception."); + e.printStackTrace(); + return false; + } catch (NullPointerException e) { + Factions.log("Failed to save the factions to disk due to NPE."); e.printStackTrace(); return false; } diff --git a/src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java b/src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java index 39813778..8e349171 100644 --- a/src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java +++ b/src/com/bukkit/mcteam/factions/MyLocationTypeAdapter.java @@ -38,7 +38,18 @@ public class MyLocationTypeAdapter implements JsonDeserializer, JsonSe @Override public JsonElement serialize(Location src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); - + + if (src == null) + { + Factions.log("Passed location is null in MyLocationTypeAdapter."); + return obj; + } + else if (src.getWorld() == null) + { + Factions.log("Passed location's world is null in MyLocationTypeAdapter."); + return obj; + } + obj.addProperty(WORLD, src.getWorld().getName()); obj.addProperty(X, src.getX()); obj.addProperty(Y, src.getY());