From a27bdf232cd12314cad5b76f0f463d468ef76cc7 Mon Sep 17 00:00:00 2001 From: Madeline Miller Date: Sun, 7 Jul 2024 16:10:30 +1000 Subject: [PATCH] keep the platform lock until preferences are updated in #unregister --- .../extension/platform/PlatformManager.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index ce85d1208f..f5118329ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -141,36 +141,36 @@ public boolean unregister(Platform platform) { try { removed = platforms.remove(platform); - } finally { - platformsLock.writeLock().unlock(); - } - if (removed) { - LOGGER.info("Unregistering " + platform.getClass().getCanonicalName() + " from WorldEdit"); + if (removed) { + LOGGER.info("Unregistering " + platform.getClass().getCanonicalName() + " from WorldEdit"); - boolean choosePreferred = false; + boolean choosePreferred = false; - preferencesLock.writeLock().lock(); + preferencesLock.writeLock().lock(); - try { - // Check whether this platform was chosen to be the preferred one - // for any capability and be sure to remove it - Iterator> it = preferences.entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - if (entry.getValue().equals(platform)) { - entry.getKey().uninitialize(this, entry.getValue()); - it.remove(); - choosePreferred = true; // Have to choose new favorites + try { + // Check whether this platform was chosen to be the preferred one + // for any capability and be sure to remove it + Iterator> it = preferences.entrySet().iterator(); + while (it.hasNext()) { + Entry entry = it.next(); + if (entry.getValue().equals(platform)) { + entry.getKey().uninitialize(this, entry.getValue()); + it.remove(); + choosePreferred = true; // Have to choose new favorites + } } + } finally { + preferencesLock.writeLock().unlock(); } - } finally { - preferencesLock.writeLock().unlock(); - } - if (choosePreferred) { - choosePreferred(); + if (choosePreferred) { + choosePreferred(); + } } + } finally { + platformsLock.writeLock().unlock(); } return removed;