From 1b174804c7f619a94fdb3f3419020e17992d29b2 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Sat, 21 Sep 2024 19:57:08 +0200 Subject: [PATCH] Return null in getRegistry(Class) for unknown type (#11422) The Bukkit#getRegistry(Class) method contract specifies that it returns null for unknown registry types. The current implementation however requires the passed class to be mappable to a known registry key. For types like Material, which have a SimpleRegistry in bukkit's Registry interface, no server side registry exists and such the type cannot be mapped to a registry key. The commit correctly returns null for types that are not mappable to a registry key instead of throwing a NullPointerException. --- .../Add-RegistryAccess-for-managing-Registries.patch | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/patches/server/Add-RegistryAccess-for-managing-Registries.patch b/patches/server/Add-RegistryAccess-for-managing-Registries.patch index bde3b899be..b1b83d7c1a 100644 --- a/patches/server/Add-RegistryAccess-for-managing-Registries.patch +++ b/patches/server/Add-RegistryAccess-for-managing-Registries.patch @@ -213,10 +213,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @Deprecated(forRemoval = true) + @Override + public @Nullable Registry getRegistry(final Class type) { -+ final RegistryKey registryKey; -+ final @Nullable RegistryEntry entry; -+ registryKey = requireNonNull(byType(type), () -> type + " is not a valid registry type"); -+ entry = PaperRegistries.getEntry(registryKey); ++ final @Nullable RegistryKey registryKey = byType(type); ++ // If our mapping from Class -> RegistryKey did not contain the passed type it was either a completely invalid type or a registry ++ // that merely exists as a SimpleRegistry in the org.bukkit.Registry type. We cannot return a registry for these, return null ++ // as per method contract in Bukkit#getRegistry. ++ if (registryKey == null) return null; ++ ++ final @Nullable RegistryEntry entry = PaperRegistries.getEntry(registryKey); + final @Nullable RegistryHolder registry = (RegistryHolder) this.registries.get(registryKey); + if (registry != null) { + // if the registry exists, return right away. Since this is the "legacy" method, we return DelayedRegistry