Skip to content

Commit

Permalink
keep the platform lock until preferences are updated in #unregister
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Jul 7, 2024
1 parent 0ac7a04 commit a27bdf2
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entry<Capability, Platform>> it = preferences.entrySet().iterator();
while (it.hasNext()) {
Entry<Capability, Platform> 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<Entry<Capability, Platform>> it = preferences.entrySet().iterator();
while (it.hasNext()) {
Entry<Capability, Platform> 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;
Expand Down

0 comments on commit a27bdf2

Please sign in to comment.