diff --git a/game-app/game-headed/src/main/java/games/strategy/triplea/ui/TripleAFrame.java b/game-app/game-headed/src/main/java/games/strategy/triplea/ui/TripleAFrame.java index 6c33b4e9609..40eb389cda0 100644 --- a/game-app/game-headed/src/main/java/games/strategy/triplea/ui/TripleAFrame.java +++ b/game-app/game-headed/src/main/java/games/strategy/triplea/ui/TripleAFrame.java @@ -109,6 +109,7 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; @@ -706,14 +707,7 @@ public FightBattleDetails getBattle( public void notifyError(final String message) { final String displayMessage = LocalizeHtml.localizeImgLinksInHtml(message, uiContext.getMapLocation()); - messageAndDialogThreadPool.submit( - () -> - EventThreadJOptionPane.showMessageDialogWithScrollPane( - TripleAFrame.this, - displayMessage, - "Error", - JOptionPane.ERROR_MESSAGE, - getUiContext().getCountDownLatchHandler())); + showMessageDialog(displayMessage, "Error", JOptionPane.ERROR_MESSAGE); } /** We do NOT want to block the next player from beginning their turn. */ @@ -742,14 +736,22 @@ public void notifyMessage(final String message, final String title) { } final String displayMessage = LocalizeHtml.localizeImgLinksInHtml(message, uiContext.getMapLocation()); - messageAndDialogThreadPool.submit( - () -> - EventThreadJOptionPane.showMessageDialogWithScrollPane( - TripleAFrame.this, - displayMessage, - title, - JOptionPane.INFORMATION_MESSAGE, - getUiContext().getCountDownLatchHandler())); + showMessageDialog(displayMessage, title, JOptionPane.INFORMATION_MESSAGE); + } + + private void showMessageDialog(String displayMessage, String title, int type) { + try { + messageAndDialogThreadPool.submit( + () -> + EventThreadJOptionPane.showMessageDialogWithScrollPane( + TripleAFrame.this, + displayMessage, + title, + type, + getUiContext().getCountDownLatchHandler())); + } catch (RejectedExecutionException e) { + // The thread pool may have been shutdown. Nothing to do. + } } /**