[SPIGOT-5315] ItemStack of ARMOR_STAND with ItemMeta can't be deeply serialized Created: 09/Sep/19 Updated: 11/Sep/19 Resolved: 11/Sep/19 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Jan Polák | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | bug, serialization | ||
| Version: | CraftBukkit version git-Spigot-065a373-03b145b (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT) |
| Guidelines Read: | Yes |
| Description |
|
The following code: final ItemStack itemStack = new ItemStack(Material.ARMOR_STAND); final ItemMeta meta = itemStack.getItemMeta(); meta.setDisplayName("Custom name"); itemStack.setItemMeta(meta); System.out.println(itemStack.toString());// or itemStack.serialize() (in Plugin.onEnable(), but not limited to there) causes following exception: java.lang.NullPointerException: null value in entry: meta-type=null at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:34) ~[spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at com.google.common.collect.ImmutableMapEntry.<init>(ImmutableMapEntry.java:49) ~[spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:172) ~[spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:248) ~[spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at org.bukkit.craftbukkit.v1_14_R1.inventory.CraftMetaItem.serialize(CraftMetaItem.java:1222) ~[spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at org.bukkit.craftbukkit.v1_14_R1.inventory.CraftMetaItem.toString(CraftMetaItem.java:1372) ~[spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at java.lang.String.valueOf(String.java:2994) ~[?:1.8.0_151] at java.lang.StringBuilder.append(StringBuilder.java:131) ~[?:1.8.0_151] at org.bukkit.inventory.ItemStack.toString(ItemStack.java:237) ~[spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at com.darkyen.minecraft.PLUGINNAME.onEnable(PLUGINNAME.java:319) ~[?:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) [spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:461) [spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:375) [spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:449) [spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at net.minecraft.server.v1_14_R1.DedicatedServer.init(DedicatedServer.java:266) [spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:775) [spigot-1.14.4.jar:git-Spigot-065a373-03b145b] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151] Calling toString on the ItemStack or the result of its serialization is only needed to force a deep serialization of the CraftMetaItem, the issue is present even when serializing manually and is not limited to the toString method. This may be a possible regression as I have encountered it in my own tests which had worked before the server update from an older 1.14.4 build. |
| Comments |
| Comment by blablubbabc [ 09/Sep/19 ] |
|
Seems like CraftMetaItem.SerializableMeta#classMap is missing an entry for CraftMetaArmorStand. It might also make sense to add CraftMetaArmorStand#ENTITY_TAG to the getHandledTags in CraftMetaItem (though, this is not causing any issues currently since the same tag gets already added due to CraftMetaSpawnEgg).
|
| Comment by Jan Polák [ 09/Sep/19 ] |
|
Yes, this is using that API, the serialize() is of the interface ConfigurationSerializable. toString() should never throw an exception, IMO. |
| Comment by Black Hole [ 09/Sep/19 ] |
|
ItemStacks in Spigot support a feature called configuration serializeable. The API doesn't promise that serialize() or that toString() works. |