PaperMC / PaperMC/Paper

Incorrect serialisation or deserialisation causes not deserializable ItemStacks

Open
#9,056 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: accepted type: bug upstream: bukkit version: 1.19
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

Expected behavior

Be able to load the serialized ItemStack from yaml

Observed/Actual behavior

The following exception: https://cpaste.de/xisomajoto.sql

Steps/models to reproduce

The ItemStack is modified like this:

        ItemMeta itemMeta = item.getItemMeta();
        PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer();
        // String content = new JSONArray(activeArmorParticleNamesList).toString();
        String content = "[\"UnicornParticle\",\"TotemParticle\",\"AngelParticle\",\"ColorSwitchParticle\"]"
        persistentDataContainer.set(plugin.getAddedParticlesNamespacedKey(), PersistentDataType.STRING, content);
        item.setItemMeta(itemMeta);

Now I am now serializing and then deserializing the ItemStack like this:

        YamlConfiguration conf = new YamlConfiguration();
        conf.set("item", item2);
        YamlConfiguration conf2 = new YamlConfiguration();
        try {
            conf2.loadFromString(conf.saveToString());
        } catch (Exception e) {
            Bukkit.getLogger().log(Level.SEVERE, conf.saveToString(), e);
        }
Plugin and Datapack List

n/a

Paper version

git-Paper-"38be4f8" (MC: 1.19.4) (Implementing API version 1.19.4-R0.1-SNAPSHOT) (Git: 38be4f8)

Other

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the YamlConfiguration save/load sequence with an ItemStack containing the PersistentDataContainer string shown in the issue, then inspect the linked exception details. No repository file or test is named, so trace the ItemStack serialization and deserialization entry points and add a regression test once the failure path is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.