In 1.20.4 and older it was easily possible to create items with plain strings instead of JSON formatting as names, as the JSON inside the NBT tag was not properly validated on creation or saving.
Loading items created in those versions in 1.21.8 now throws an exception on load. The item name will still correctly be upgraded to a custom_name
component however.
Exception:
[03:48:17] [Render thread/ERROR]: Failed to unflatten text component json: Evil stick
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed JSON at line 1 column 7 path $
See https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json
at com.google.gson.JsonParser.parseReader(JsonParser.java:116) ~[gson-2.11.0.jar:?]
at com.google.gson.JsonParser.parseString(JsonParser.java:92) ~[gson-2.11.0.jar:?]
at bbw.a(SourceFile:22) ~[1.21.8.jar:?]
at bmv.a(SourceFile:40) ~[1.21.8.jar:?]
at bmv.a(SourceFile:34) ~[1.21.8.jar:?]
at java.base/java.util.function.Function.lambda$compose$0(Function.java:68) ~[?:?]
at java.base/java.util.function.Function.lambda$compose$0(Function.java:68) ~[?:?]
at com.mojang.datafixers.util.Either.lambda$mapRight$1(Either.java:166) ~[datafixerupper-8.0.16.jar:?]
[...]
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed JSON at line 1 column 7 path $
See https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1754) ~[gson-2.11.0.jar:?]
at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1550) ~[gson-2.11.0.jar:?]
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:625) ~[gson-2.11.0.jar:?]
at com.google.gson.stream.JsonReader.peek(JsonReader.java:507) ~[gson-2.11.0.jar:?]
at com.google.gson.JsonParser.parseReader(JsonParser.java:111) ~[gson-2.11.0.jar:?]
Reproduction steps:
Use 1.20.4 or older. Anything newer than 1.12 works.
Run
/give @p stick{display:{Name:'Evil stick'}}
. Make sure to test in survival mode.Verify the NBT data with /data get. The
Display
tag will have been set to the plain string.Log off/on or save the world, note that it saves fine without any errors or exceptions in the old version.
Update the world to e.g. 1.21.8.
You will get the exception above when loading the player inventory
This is especially an issue on longer-running servers, where there might be thousands upon thousands of player or container inventories with such items in them.
Related PaperMC issue with a bunch of other examples and user reports: https://github.com/PaperMC/Paper/issues/12873
For clarification it may be good to point out this started in 1.21.5 when that data fix was first put in place, not only in 1.21.8