Skip to content

ClickEvent.Payload.custom should allow null payload instead of throwing NPE #1326

@jhqwqmc

Description

@jhqwqmc

According to the documentation:

Image

https://minecraft.wiki/w/Text_component_format#custom

The payload field is marked as optional — it should be allowed to be null.
However, when payload is null, the following error occurs:

[19:11:48] [Netty Epoll Server IO #0/WARN]: [CraftEngine] An error occurred when handling packet ClientboundSystemChatPacket
java.lang.NullPointerException: string
    at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]
    at net.momirealms.craftengine.libraries.adventure.nbt.api.BinaryTagHolderImpl.<init>(BinaryTagHolderImpl.java:35) ~[adventure-api-4.25.0-remapped.jar:?]
    at net.momirealms.craftengine.libraries.adventure.nbt.api.BinaryTagHolder.binaryTagHolder(BinaryTagHolder.java:65) ~[adventure-api-4.25.0-remapped.jar:?]
    at net.momirealms.craftengine.libraries.adventure.text.event.ClickEvent$Payload.custom(ClickEvent.java:402) ~[adventure-api-4.25.0-remapped.jar:?]

This suggests that BinaryTagHolder does not handle null correctly, even though the documentation indicates that the field is optional.
https://github.com/KyoriPowered/adventure/blob/cbad048c7199fdec87d7aab20a8cfce09957a21a/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolderImpl.java#L34-L35
https://github.com/KyoriPowered/adventure/blob/cbad048c7199fdec87d7aab20a8cfce09957a21a/api/src/main/java/net/kyori/adventure/text/event/ClickEvent.java#L416-L418
It would be more consistent if ClickEvent.Payload.custom or BinaryTagHolder accepted null as a valid value for an absent payload instead of throwing a NullPointerException.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions