From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 15 May 2023 00:20:59 -0700 Subject: [PATCH] Fix concurrenct access to lookups field in RegistryOps The concurrent access occurs on the Netty IO threads when serializing packets. Thus, it seems it was an oversight of the implementator of this function as there are typically more than one Netty IO thread. Fixes https://github.com/PaperMC/Folia/issues/11 diff --git a/src/main/java/net/minecraft/resources/RegistryOps.java b/src/main/java/net/minecraft/resources/RegistryOps.java index e682e40b2c82c6d47dcaa6a3ff56a2e1f14f422f..1722c88c93cf8a09a9acb37e838b137c0e5cde64 100644 --- a/src/main/java/net/minecraft/resources/RegistryOps.java +++ b/src/main/java/net/minecraft/resources/RegistryOps.java @@ -19,11 +19,11 @@ public class RegistryOps extends DelegatingOps { private static RegistryOps.RegistryInfoLookup memoizeLookup(final RegistryOps.RegistryInfoLookup registryInfoGetter) { return new RegistryOps.RegistryInfoLookup() { - private final Map>, Optional>> lookups = new HashMap<>(); + private final Map>, Optional>> lookups = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - fix concurrent access to lookups field @Override public Optional> lookup(ResourceKey> registryRef) { - return this.lookups.computeIfAbsent(registryRef, registryInfoGetter::lookup); + return (Optional>)this.lookups.computeIfAbsent(registryRef, registryInfoGetter::lookup); // Paper - fix concurrent access to lookups field } }; }