Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected exception in ItemDatabase update #563

Merged
merged 2 commits into from
Aug 14, 2023

Conversation

Joo200
Copy link
Contributor

@Joo200 Joo200 commented Aug 14, 2023

After some update of ChestShop i noticed a stacktrace from ChestShop in the server logs.

Looks like my database has a lots of corrupted items but as long as most items can be updated I'm fine with that. In my case the item is corrupted and can't be deserialized, which results in some uncatched ClassCastException.

My fix is to add this exception to the catch block.

[17:47:22] [Server thread/ERROR]: [ChestShop] YAML of the item with ID c (12) is corrupted: 
==: org.bukkit.inventory.ItemStack
type: EXP_BOTTLE
meta: &id001
  ==: *id001
  meta-type: UNSPECIFIC
  display-name: Bottle of Wisdom

[17:47:22] [Server thread/ERROR]: [ChestShop] YAML of the item with ID d (13) is corrupted: 
&id001
==: *id001
type: EXP_BOTTLE
meta: {==: ItemMeta, meta-type: UNSPECIFIC, display-name: Bottle of Wisdom}

[17:47:22] [Server thread/ERROR]: [ChestShop] Item with ID e (14) is corrupted. Sorry :(
[17:47:22] [Server thread/ERROR]: [ChestShop] Item with ID f (15) is corrupted. Sorry :(
[17:47:22] [Server thread/ERROR]: [ChestShop] YAML of the item with ID g (16) is corrupted: 
&id001
==: org.bukkit.inventory.ItemStack
type: *id001
meta: &id002
  *id002: ItemMeta
  meta-type: UNSPECIFIC
  display-name: Bottle of Wisdom

[17:47:22] [Server thread/WARN]: java.sql.SQLException: Batch tasks callable threw non-SQL exception
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Libs.ORMlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:27)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Libs.ORMlite.stmt.StatementExecutor.doCallBatchTasks(StatementExecutor.java:653)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Libs.ORMlite.stmt.StatementExecutor.doCallBatchTasks(StatementExecutor.java:619)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Libs.ORMlite.stmt.StatementExecutor.callBatchTasks(StatementExecutor.java:598)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Libs.ORMlite.dao.BaseDaoImpl.callBatchTasks(BaseDaoImpl.java:724)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Metadata.ItemDatabase.updateMetadataVersion(ItemDatabase.java:91)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Metadata.ItemDatabase.handleMetadataUpdate(ItemDatabase.java:57)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Metadata.ItemDatabase.<init>(ItemDatabase.java:44)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.ChestShop.onEnable(ChestShop.java:144)
[17:47:22] [Server thread/WARN]: 	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281)
[17:47:22] [Server thread/WARN]: 	at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:189)
[17:47:22] [Server thread/WARN]: 	at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104)
[17:47:22] [Server thread/WARN]: 	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507)
[17:47:22] [Server thread/WARN]: 	at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugin(CraftServer.java:639)
[17:47:22] [Server thread/WARN]: 	at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugins(CraftServer.java:550)
[17:47:22] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:636)
[17:47:22] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:435)
[17:47:22] [Server thread/WARN]: 	at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:308)
[17:47:22] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1101)
[17:47:22] [Server thread/WARN]: 	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:318)
[17:47:22] [Server thread/WARN]: 	at java.base/java.lang.Thread.run(Thread.java:833)
[17:47:22] [Server thread/WARN]: Caused by: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_20_R1.inventory.CraftMetaItem cannot be cast to class java.lang.String (org.bukkit.craftbukkit.v1_20_R1.inventory.CraftMetaItem is in unnamed module of loader java.net.URLClassLoader @2b71fc7e; java.lang.String is in module java.base of loader 'bootstrap')
[17:47:22] [Server thread/WARN]: 	at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:200)
[17:47:22] [Server thread/WARN]: 	at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:58)
[17:47:22] [Server thread/WARN]: 	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:264)
[17:47:22] [Server thread/WARN]: 	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:247)
[17:47:22] [Server thread/WARN]: 	at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:201)
[17:47:22] [Server thread/WARN]: 	at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:185)
[17:47:22] [Server thread/WARN]: 	at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:493)
[17:47:22] [Server thread/WARN]: 	at org.yaml.snakeyaml.Yaml.loadAs(Yaml.java:473)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Metadata.ItemDatabase.lambda$updateMetadataVersion$0(ItemDatabase.java:100)
[17:47:22] [Server thread/WARN]: 	at ChestShop.jar//com.Acrobot.ChestShop.Libs.ORMlite.stmt.StatementExecutor.doCallBatchTasks(StatementExecutor.java:649)
[17:47:22] [Server thread/WARN]: 	... 19 more
[17:47:22] [Server thread/WARN]: [ChestShop] Error while updating Item Metadata database! While the plugin will still run it will work less efficiently.

@Phoenix616
Copy link
Member

I'm a bit confused why this error would even happen in the first place. Which item data/string is causing this?

@Phoenix616
Copy link
Member

Also seeing as the error is thrown with the actual YAML known it should probably be caught here:

} catch (YAMLException e) {
ChestShop.getBukkitLogger().log(Level.SEVERE, "YAML of the item with ID " + Base62.encode(item.getId()) + " (" + item.getId() + ") is corrupted: \n" + serialized);
}

@Joo200
Copy link
Contributor Author

Joo200 commented Aug 14, 2023

I'm not sure how the item was created. The item deserialized is:

==: {==: ItemMeta, meta-type: UNSPECIFIC, display-name: Bottle of Wisdom}
type: EXP_BOTTLE
meta: {==: ItemMeta, meta-type: UNSPECIFIC, display-name: Bottle of Wisdom}

The raw base64 value is:

rO0ABXQApz09OiB7PT06IEl0ZW1NZXRhLCBtZXRhLXR5cGU6IFVOU1BFQ0lGSUMsIGRpc3BsYXktbmFtZTogQm90dGxlIG9mIFdpc2RvbX0KdHlwZTogRVhQX0JPVFRMRQptZXRhOiB7PT06IEl0ZW1NZXRhLCBtZXRhLXR5cGU6IFVOU1BFQ0lGSUMsIGRpc3BsYXktbmFtZTogQm90dGxlIG9mIFdpc2RvbX0K

I agree we should move this to the YAMLException instead.

@Joo200 Joo200 closed this Aug 14, 2023
@Joo200 Joo200 reopened this Aug 14, 2023
@Phoenix616
Copy link
Member

Yeah that unfortunately looks like the usual YAML chanenigans :S I guess I need to look into how to disable some of the substitution/variable systems in the serializer as this seems to happen quite often...

Thanks for bringing this up and directly writing a PR for it though! Looks good now :)

@Phoenix616 Phoenix616 merged commit f3cf4cd into ChestShop-authors:master Aug 14, 2023
1 check passed
@Joo200
Copy link
Contributor Author

Joo200 commented Aug 14, 2023

A small note after the quick merge (thanks for that):

I guess I need to look into how to disable some of the substitution/variable systems in the serializer as this seems to happen quite often...

I'm pretty sure those issues are already resolved in the current releases from ChestShop. The items with those exceptions were created a few years ago (i guess 2015), newer items don't have such problems. I can send you the items.db with data since 2015 if you want to test those issues but personally I wouldn't invest much time in 8 years old stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants