Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions patches/server/0920-Fix-CraftPersistentDataTypeRegistry-CME.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Gero <gecam59@gmail.com>
Date: Sat, 1 Oct 2022 19:43:27 +0200
Subject: [PATCH] Fix CraftPersistentDataTypeRegistry CME


diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataTypeRegistry.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataTypeRegistry.java
index 355c9f79fd3132848a00eacde951d1e1bfa92737..f39b6d8eae3533d2795036e863566f61ebce53ea 100644
--- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataTypeRegistry.java
+++ b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataTypeRegistry.java
@@ -93,6 +93,15 @@ public final class CraftPersistentDataTypeRegistry {
}

private final Map<Class, TagAdapter> adapters = new HashMap<>();
+ // Paper start - Fix CME
+ private TagAdapter getAdapter(Class type) {
+ TagAdapter adapter = this.adapters.get(type);
+ if (adapter != null) return adapter;
+ synchronized (this.adapters) {
+ return this.adapters.computeIfAbsent(type, CREATE_ADAPTER);
+ }
+ }
+ // Paper end - Fix CME

/**
* Creates a suitable adapter instance for the primitive class type
@@ -212,7 +221,7 @@ public final class CraftPersistentDataTypeRegistry {
* type was found
*/
public <T> Tag wrap(Class<T> type, T value) {
- return this.adapters.computeIfAbsent(type, CREATE_ADAPTER).build(value);
+ return getAdapter(type).build(value); // Paper - Fix CME
}

/**
@@ -228,7 +237,7 @@ public final class CraftPersistentDataTypeRegistry {
* type was found
*/
public <T> boolean isInstanceOf(Class<T> type, Tag base) {
- return this.adapters.computeIfAbsent(type, CREATE_ADAPTER).isInstance(base);
+ return getAdapter(type).isInstance(base); // Paper - Fix CME
}

/**
@@ -249,7 +258,7 @@ public final class CraftPersistentDataTypeRegistry {
* type was found
*/
public <T> T extract(Class<T> type, Tag tag) throws ClassCastException, IllegalArgumentException {
- TagAdapter adapter = this.adapters.computeIfAbsent(type, CREATE_ADAPTER);
+ TagAdapter adapter = getAdapter(type); // Paper - Fix CME
if (!adapter.isInstance(tag)) {
throw new IllegalArgumentException(String.format("`The found tag instance cannot store %s as it is a %s", type.getSimpleName(), tag.getClass().getSimpleName()));
}