From 0ddf6688c9c84470626bbd4a424fb6e31dd92fba Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Fri, 8 Oct 2021 00:00:22 +0200 Subject: [PATCH] Return a dummy when recipe deserialization fails. Closes #2563. (#2565). Thanks to Technici4n --- .../common/crafting/RebornRecipeType.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java b/RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java index 4c2fcaa52..20624d715 100644 --- a/RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java +++ b/RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java @@ -49,21 +49,24 @@ public record RebornRecipeType( throw new RuntimeException("RebornRecipe type not supported!"); } - R recipe = newRecipe(recipeId); - try { + R recipe = newRecipe(recipeId); + if (!ConditionManager.shouldLoadRecipe(json)) { recipe.makeDummy(); return recipe; } recipe.deserialize(json); + return recipe; } catch (Throwable t) { - t.printStackTrace(); - RebornCore.LOGGER.error("Failed to read recipe: " + recipeId); + RebornCore.LOGGER.error("Failed to read recipe: " + recipeId, t); + // Make a new recipe - don't reuse the existing recipe object because it might be in an invalid state if an + // exception was thrown in the middle of its deserialization. + R recipe = newRecipe(recipeId); + recipe.makeDummy(); + return recipe; } - return recipe; - } public JsonObject toJson(R recipe) {