[SPIGOT-6260] ItemStack#isSimilar() no longer work after the item is deserialized Created: 30/Nov/20  Updated: 30/Nov/20  Resolved: 30/Nov/20

Status: Closed
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: wysohn Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: 1.16.4, itemstack, serialization

Attachments: PNG File Screenshot from 2020-11-29 22-24-46.png     PNG File Screenshot from 2020-11-29 22-24-53.png     PNG File Screenshot from 2020-11-29 22-24-57.png     PNG File Screenshot from 2020-11-29 22-25-49.png     PNG File Screenshot from 2020-11-29 22-27-18.png     PNG File Screenshot from 2020-11-29 22-30-05.png    
Version: This server is running CraftBukkit version git-Spigot-a19903d-e1ebdd9 (MC: 1.16.4) (Implementing API version 1.16.4-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

So it is quite straight forward.

Whenever an item's name is modified by the anvil, serialized, and then de-serialized, then isSimilar() now no longer able to tell they are the similar items.

Take a look at the screenshots for details.

Steps:

  1. Rename any item with anvil
  2. Copy the item through creative inventory (As shown in the screenshot)
  3. Check if they are indeed similar. At this point, they are similar as shown in screenshot.
  4. Now, do the following steps
    1. Save item using the FileConfiguration (using getConfig() method of the JavaPlugin class)
    2. Save the FileConfiguration into String
    3. Create a new YamlConfiguration and load the serialized String from 4.2.
    4. Get the ItemStack from the YamlConfiguration
  5. Now, again, check if they are similar just like I did in process 3.
  6. Now isSimilar() returns false for some unknown reason.

Since the toString() of both ItemStack shows exactly same output, I assume something is internally failing.

I think this is a major issue since it's a quite basic functionality. Item name is something that can be easily changed in-game without any plugins. Plugins that rely on isSimilar() method will be severely impacted by this problem.

Thanks!

PS) test code attached here

 



 Comments   
Comment by Black Hole [ 30/Nov/20 ]

Duplicate of SPIGOT-5063 (root cause) and SPIGOT-5304 (more specific)

Generated at Fri Apr 11 16:00:47 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.