-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
None
-
This server is running CraftBukkit version git-Spigot-2f5d615-d07a78b (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)
-
Yes
When loading YAML with an ItemStack serialized in it, it is impossible to catch errors if the ItemStack has an error, e.g., if the material is spelled wrong. Expected operation would be that an exception would be thrown when loading that can be caught and handled. Further, the stack trace that is dumped provides no useful information on where the error occurred in the file or what was the cause.
For example, this config file will load fine:
'0': chests: '1': contents: 1: ==: org.bukkit.inventory.ItemStack v: 2230 type: OAK_SAPLING
This next config file has an error and dumps a lot of stack trace to the console when loading, but still loads without throwing any exceptions:
'0': chests: '1': contents: 1: ==: org.bukkit.inventory.ItemStack v: 2230 type: OAK_SAPLNG
Currently, it's not possible to catch this error when loading the YAML via YamlConfiguration.load.
Here's the test plugin onEnable. The JAR has two yaml files in it, one that is good and one that is bad:
@Override public void onEnable() { Bukkit.getLogger().info("Saving resources"); this.saveResource("goodItemStack.yml", true); this.saveResource("badItemStack.yml", true); Bukkit.getLogger().info("Trying the load config files"); YamlConfiguration chestConfig = new YamlConfiguration(); File good = new File(this.getDataFolder(), "goodItemStack.yml"); try { chestConfig.load(good); } catch (IOException | InvalidConfigurationException e) { Bukkit.getLogger().severe("There was a problem loading file " + good.getName() + " " + e.getMessage()); } Bukkit.getLogger().info("Loaded " + good.getName()); File bad = new File(this.getDataFolder(), "badItemStack.yml"); try { chestConfig.load(bad); } catch (IOException | InvalidConfigurationException e) { // This catch never catches the ItemStack deserialization error Bukkit.getLogger().severe("There was a problem loading file " + bad.getName() + " " + e.getMessage()); } Bukkit.getLogger().info("Loaded " + bad.getName()); }
In theory, the error in the badItemStack.yml should be catchable, however, this is the console log:
[16:53:21] [Server thread/INFO]: [TestPlugin] Enabling TestPlugin v1.0 [16:53:21] [Server thread/INFO]: Saving resources [16:53:21] [Server thread/INFO]: Trying the load config files [16:53:21] [Server thread/INFO]: Loaded goodItemStack.yml [16:53:21] [Server thread/ERROR]: Could not call method 'public static org.bukkit.inventory.ItemStack org.bukkit.inventory.ItemStack.deserialize(java.util.Map)' of class org.bukkit.inventory.ItemStack for deserialization java.lang.IllegalArgumentException: Material cannot be null at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.inventory.ItemStack.<init>(ItemStack.java:82) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.inventory.ItemStack.<init>(ItemStack.java:70) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.inventory.ItemStack.deserialize(ItemStack.java:508) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at jdk.internal.reflect.GeneratedMethodAccessor10.invoke(Unknown Source) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?] at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeViaMethod(ConfigurationSerialization.java:85) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.serialization.ConfigurationSerialization.deserialize(ConfigurationSerialization.java:127) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:207) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:37) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:216) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:205) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:465) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:184) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:446) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:521) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:28) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:216) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:205) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:465) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:184) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:446) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:521) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:28) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:216) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:205) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:465) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:184) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:446) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:521) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:28) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:216) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:205) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:465) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:184) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:446) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:521) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:28) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:216) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:205) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:465) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:184) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:446) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:521) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:28) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:216) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:205) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:164) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:148) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:525) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.yaml.snakeyaml.Yaml.load(Yaml.java:438) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:54) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:160) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:128) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at us.tastybento.test.TestPlugin.onEnable(TestPlugin.java:31) [TestPlugin-1.11.1-SNAPSHOT-LOCAL.jar:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:464) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:378) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.craftbukkit.v1_15_R1.CraftServer.reload(CraftServer.java:835) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.Bukkit.reload(Bukkit.java:620) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchCommand(CraftServer.java:723) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchServerCommand(CraftServer.java:708) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at net.minecraft.server.v1_15_R1.DedicatedServer.handleCommandQueue(DedicatedServer.java:443) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at net.minecraft.server.v1_15_R1.DedicatedServer.b(DedicatedServer.java:407) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:984) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:824) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b] at java.lang.Thread.run(Thread.java:834) [?:?] [16:53:21] [Server thread/INFO]: Loaded badItemStack.yml
In addition to the exception being uncatchable, the stack trace itself gives no indication of what the error is or where it is in the file. It would be good to report the incorrect material name used and ideally the line number where it occurred.
Thanks for your consideration!