Ver código fonte

Don't hold locks while calling identity listeners

Fixes deadlock when setting some options to their default values

Change-Id: Ibfb91261db177bc7cdcd8d9d594fecbed789b718
Reviewed-on: http://gerrit.dmdirc.com/732
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
tags/0.6.3b1
Chris Smith 14 anos atrás
pai
commit
5a8238e4d8
1 arquivos alterados com 15 adições e 6 exclusões
  1. 15
    6
      src/com/dmdirc/config/Identity.java

+ 15
- 6
src/com/dmdirc/config/Identity.java Ver arquivo

@@ -348,6 +348,7 @@ public class Identity extends ConfigSource implements Serializable,
348 348
     public void setOption(final String domain, final String option,
349 349
             final String value) {
350 350
         String oldValue;
351
+        boolean unset = false;
351 352
 
352 353
         synchronized (this) {
353 354
             oldValue = getOption(domain, option);
@@ -365,23 +366,31 @@ public class Identity extends ConfigSource implements Serializable,
365 366
 
366 367
                 if (globalConfig.hasOption(domain, option)
367 368
                         && globalConfig.getOption(domain, option).equals(value)) {
369
+                    // The new value is covered by a default setting
368 370
                     if (oldValue == null) {
371
+                        // There was no old value, so we don't need to do anything
369 372
                         return;
370 373
                     } else {
371
-                        unsetOption(domain, option);
372
-                        return;
374
+                        // There was an old value, so we need to unset it so
375
+                        // that the default shows through.
376
+                        file.getKeyDomain(domain).remove(option);
377
+                        needSave = true;
378
+                        unset = true;
373 379
                     }
374 380
                 }
375 381
             }
376
-        }
377 382
 
378
-        if ((oldValue == null && value != null)
379
-                || (oldValue != null && !oldValue.equals(value))) {
380
-            synchronized (this) {
383
+            if (!unset && ((oldValue == null && value != null)
384
+                    || (oldValue != null && !oldValue.equals(value)))) {
381 385
                 file.getKeyDomain(domain).put(option, value);
382 386
                 needSave = true;
383 387
             }
388
+        }
384 389
 
390
+        // Fire any setting change listeners now we're no longer holding
391
+        // a lock on this identity.
392
+        if (unset || (oldValue == null && value != null)
393
+                || (oldValue != null && !oldValue.equals(value))) {
385 394
             fireSettingChange(domain, option);
386 395
         }
387 396
     }

Carregando…
Cancelar
Salvar