From 5efb12fdb3898a1ccfa8028959caa50397a3c0b1 Mon Sep 17 00:00:00 2001 From: asvitkine Date: Sun, 1 Oct 2023 12:52:30 -0400 Subject: [PATCH 1/2] Fix a RejectedExecutionException. --- .../strategy/triplea/ui/TripleAFrame.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) 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..9e381fd34fc 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"); } /** 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); + } + + private void showMessageDialog(String displayMessage, String title) { + try { + messageAndDialogThreadPool.submit( + () -> + EventThreadJOptionPane.showMessageDialogWithScrollPane( + TripleAFrame.this, + displayMessage, + title, + JOptionPane.INFORMATION_MESSAGE, + getUiContext().getCountDownLatchHandler())); + } catch (RejectedExecutionException e) { + // The thread pool may have been shutdown. Nothing to do. + } } /** From 631892a125079f248c195d75406041d9a170ff40 Mon Sep 17 00:00:00 2001 From: asvitkine Date: Sun, 1 Oct 2023 12:53:43 -0400 Subject: [PATCH 2/2] Keep message type. --- .../main/java/games/strategy/triplea/ui/TripleAFrame.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 9e381fd34fc..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 @@ -707,7 +707,7 @@ public FightBattleDetails getBattle( public void notifyError(final String message) { final String displayMessage = LocalizeHtml.localizeImgLinksInHtml(message, uiContext.getMapLocation()); - showMessageDialog(displayMessage, "Error"); + showMessageDialog(displayMessage, "Error", JOptionPane.ERROR_MESSAGE); } /** We do NOT want to block the next player from beginning their turn. */ @@ -736,10 +736,10 @@ public void notifyMessage(final String message, final String title) { } final String displayMessage = LocalizeHtml.localizeImgLinksInHtml(message, uiContext.getMapLocation()); - showMessageDialog(displayMessage, title); + showMessageDialog(displayMessage, title, JOptionPane.INFORMATION_MESSAGE); } - private void showMessageDialog(String displayMessage, String title) { + private void showMessageDialog(String displayMessage, String title, int type) { try { messageAndDialogThreadPool.submit( () -> @@ -747,7 +747,7 @@ private void showMessageDialog(String displayMessage, String title) { TripleAFrame.this, displayMessage, title, - JOptionPane.INFORMATION_MESSAGE, + type, getUiContext().getCountDownLatchHandler())); } catch (RejectedExecutionException e) { // The thread pool may have been shutdown. Nothing to do.