Better protection of parsing values from json

This commit is contained in:
Pahimar 2016-05-20 23:14:36 -04:00
parent 26d1e76fe1
commit 2b46fa82eb
2 changed files with 11 additions and 20 deletions

View file

@ -25,27 +25,22 @@ public class FluidStackSerializer implements JsonSerializer<FluidStack>, JsonDes
String name = null; String name = null;
NBTTagCompound tagCompound = null; NBTTagCompound tagCompound = null;
try { if (jsonObject.has(NAME) && jsonObject.get(NAME).isJsonPrimitive()) {
if (jsonObject.has(NAME) && jsonObject.get(NAME).getAsJsonPrimitive().isString()) { name = jsonObject.getAsJsonPrimitive(NAME).getAsString();
name = jsonObject.get(NAME).getAsString();
}
}
catch (IllegalStateException exception) {
} }
try { if (jsonObject.has(TAG_COMPOUND) && jsonObject.get(TAG_COMPOUND).isJsonPrimitive()) {
if (jsonObject.has(TAG_COMPOUND) && jsonObject.get(TAG_COMPOUND).getAsJsonPrimitive().isString()) {
try {
NBTBase nbtBase = JsonToNBT.func_150315_a(jsonObject.get(TAG_COMPOUND).getAsString()); NBTBase nbtBase = JsonToNBT.func_150315_a(jsonObject.get(TAG_COMPOUND).getAsString());
if (nbtBase instanceof NBTTagCompound) { if (nbtBase instanceof NBTTagCompound) {
tagCompound = (NBTTagCompound) nbtBase; tagCompound = (NBTTagCompound) nbtBase;
} }
} }
catch (NBTException e) {
}
} }
catch (IllegalStateException exception) {
}
catch (NBTException e) {
}
if (name != null) { if (name != null) {
Fluid fluid = FluidRegistry.getFluid(name); Fluid fluid = FluidRegistry.getFluid(name);

View file

@ -13,16 +13,12 @@ public class OreStackSerializer implements JsonSerializer<OreStack>, JsonDeseria
public OreStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public OreStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonObject()) { if (json.isJsonObject()) {
JsonObject jsonObject = (JsonObject) json; JsonObject jsonObject = (JsonObject) json;
try { if (jsonObject.has(NAME) && jsonObject.get(NAME).isJsonPrimitive()) {
if (jsonObject.has(NAME) && jsonObject.get(NAME).getAsJsonPrimitive().isString()) { String name = jsonObject.getAsJsonPrimitive(NAME).getAsString();
String name = jsonObject.get(NAME).getAsString(); return new OreStack(name);
return new OreStack(name);
}
}
catch (IllegalStateException exception) {
// TODO We could probably log here that an invalid piece of data was found
} }
} }