attempt to handle an NPE someone has been getting in MyLocationTypeAdapter.serialize()

This commit is contained in:
Brettflan 2011-03-28 14:38:07 -05:00
parent 62ecceca5f
commit ebde7bcc1a
2 changed files with 17 additions and 2 deletions

View File

@ -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;
}

View File

@ -38,7 +38,18 @@ public class MyLocationTypeAdapter implements JsonDeserializer<Location>, 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());