RecipeMapping serialization throws NPE
Dynious opened this issue ยท 3 comments
When converting a RecipeMapping to Json using the toJson method, the Json serialization can produce a NullPointerException from the recipeInput list. As this doesn't seem to occur with Vanilla ItemStacks and OreStacks it probably has something to do with wrapping modded ItemStacks into WrappedStacks. EDIT: This also occurs with vanilla ItemStacks. I have the feeling I'm doing something wrong.
2014-02-09 13:11:19 [INFO] [STDOUT] java.lang.NullPointerException
2014-02-09 13:11:19 [INFO] [STDOUT] at com.pahimar.ee3.api.RecipeMapping.serialize(RecipeMapping.java:112)
2014-02-09 13:11:19 [INFO] [STDOUT] at com.pahimar.ee3.api.RecipeMapping.serialize(RecipeMapping.java:10)
2014-02-09 13:11:19 [INFO] [STDOUT] at com.google.gson.TreeTypeAdapter.write(TreeTypeAdapter.java:70)
2014-02-09 13:11:19 [INFO] [STDOUT] at com.google.gson.Gson.toJson(Gson.java:586)
2014-02-09 13:11:19 [INFO] [STDOUT] at com.google.gson.Gson.toJson(Gson.java:565)
2014-02-09 13:11:19 [INFO] [STDOUT] at com.google.gson.Gson.toJson(Gson.java:520)
2014-02-09 13:11:19 [INFO] [STDOUT] at com.google.gson.Gson.toJson(Gson.java:500)
2014-02-09 13:11:19 [INFO] [STDOUT] at com.pahimar.ee3.api.RecipeMapping.toJson(RecipeMapping.java:69)
I was writing a small addon mod which added EMC values and recipes for other mods (I have the feeling you don't want dependencies for this repo). This line produced this error: https://github.com/Dynious/EE3-Addons/blob/master/java/com/dynious/ee3addons/addon/AddonBuildCraft.java#L42 . I cannot figure out why this is producing this error.
I found out what the error was (it was my fault), but the handling of this error could be better. I was not parsing a string correctly, which resulted in a WrappedStack containing a null stack. When this was added to a list and used to create a new RecipeMapping, the constructor made the inputWrappedStacks List null, which caused the serialization to produce this error. It's just as easy to not add the null WrappedStack to the list and create log a warning that this is happening. I'll probably make a PR for this.