Skip to content

Commit

Permalink
Make sure reportErrorToUser and reportInfoToUser perform Swing operat…
Browse files Browse the repository at this point in the history
…ions on AWT thread
  • Loading branch information
vlsi committed Nov 17, 2021
1 parent 5fdf092 commit c2dea2b
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -870,14 +870,17 @@ public static void reportErrorToUser(String errorMsg, String titleMsg, Exception
System.out.println(errorMsg); // NOSONAR intentional
return; // Done
}
try {
JOptionPane.showMessageDialog(instance.getMainFrame(),
formatMessage(errorMsg),
titleMsg,
JOptionPane.ERROR_MESSAGE);
} catch (HeadlessException e) {
log.warn("reportErrorToUser(\"{}\") caused", errorMsg, e);
}
String errorMessage = errorMsg;
SwingUtilities.invokeLater(() -> {
try {
JOptionPane.showMessageDialog(instance.getMainFrame(),
formatMessage(errorMessage),
titleMsg,
JOptionPane.ERROR_MESSAGE);
} catch (HeadlessException e) {
log.warn("reportErrorToUser(\"{}\") caused", errorMessage, e);
}
});
}

/**
Expand All @@ -893,14 +896,16 @@ public static void reportInfoToUser(String msg, String titleMsg) {
System.out.println(msg); // NOSONAR intentional
return; // Done
}
try {
JOptionPane.showMessageDialog(instance.getMainFrame(),
formatMessage(msg),
titleMsg,
JOptionPane.INFORMATION_MESSAGE);
} catch (HeadlessException e) {
log.warn("reportInfoToUser(\"{}\") caused", msg, e);
}
SwingUtilities.invokeLater(() -> {
try {
JOptionPane.showMessageDialog(instance.getMainFrame(),
formatMessage(msg),
titleMsg,
JOptionPane.INFORMATION_MESSAGE);
} catch (HeadlessException e) {
log.warn("reportInfoToUser(\"{}\") caused", msg, e);
}
});
}

private static JScrollPane formatMessage(String errorMsg) {
Expand Down

0 comments on commit c2dea2b

Please sign in to comment.