From 267c97200ff3127dcaac1b88f84368f1ca5bbff0 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Mon, 29 Jun 2020 16:27:45 -0600 Subject: [PATCH] FIXUP: Avoid a potential deadlock on the EDT Signed-off-by: Taylor Smock --- .../data/mapwithai/MapWithAILayerInfo.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java index 511fab3..6f35cfb 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java @@ -19,6 +19,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; +import javax.swing.SwingUtilities; + import org.openstreetmap.josm.data.StructUtils; import org.openstreetmap.josm.data.imagery.ImageryInfo; import org.openstreetmap.josm.data.preferences.BooleanProperty; @@ -71,12 +73,15 @@ public class MapWithAILayerInfo { if (instance == null) { AtomicBoolean finished = new AtomicBoolean(); instance = new MapWithAILayerInfo(() -> finished.set(true)); - while (!finished.get()) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - Logging.error(e); - Thread.currentThread().interrupt(); + // Avoid a deadlock in the EDT. + if (!SwingUtilities.isEventDispatchThread()) { + while (!finished.get()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + Logging.error(e); + Thread.currentThread().interrupt(); + } } } }