Skip to content

NPE instead IAE when using Sound.valueOf with invalid sound #13594

@TheosRee

Description

@TheosRee

Stack trace

Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.NamespacedKey.getNamespace()" because "key" is null
        at org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(CraftNamespacedKey.java:22) ~[paper-1.21.8.jar:1.21.8-60-29c8822]
        at io.papermc.paper.util.MCUtil.toResourceKey(MCUtil.java:199) ~[paper-1.21.8.jar:1.21.8-60-29c8822]
        at org.bukkit.craftbukkit.CraftRegistry.get(CraftRegistry.java:199) ~[paper-1.21.8.jar:1.21.8-60-29c8822]
        at org.bukkit.craftbukkit.CraftRegistry.get(CraftRegistry.java:132) ~[paper-1.21.8.jar:1.21.8-60-29c8822]
        at org.bukkit.craftbukkit.util.CraftMagicNumbers.get(CraftMagicNumbers.java:479) ~[paper-1.21.8.jar:1.21.8-60-29c8822]
        at org.bukkit.Sound.valueOf(Sound.java:3498) ~[paper-api-1.21.8-R0.1-SNAPSHOT.jar:?]

Plugin and Datapack List

BetonQuest

Actions to reproduce (if known)

Read from user input a sound, like minecraft:entity.player.levelup99!!!⁩⁩ and use the Sound#valueOf method (from an old api version) with it.

Paper version

This server is running Paper version 1.21.8-60-main@29c8822 (2025-09-06T21:49:13Z) (Implementing API version 1.21.8-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.4-221-c467df9 (MC: 1.21.4)

Other

I catch the IllegalArgumentException I would expect from the valueOf method. But the NamespacedKey#fromString returns null when it is an invalid key and that is passed to a method where an actual key is expected (see Sound.java).
Checking there for null like at the end of the method would throw the expected Exception instead NPE.
Other OldEnums are "affected" by that too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: lowThis issue only describes a minor inconvenience.status: acceptedDisputed bug is accepted as valid or Feature accepted as desired to be added.version: 1.21.11Game version 1.21.11version: 1.21.8Game version 1.21.8

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions