Make assertAwtThread fail loudly fix #3982

This commit is contained in:
rusefillc 2022-03-05 19:27:26 -05:00
parent e0db62b80e
commit 009da75be9
1 changed files with 25 additions and 2 deletions

View File

@ -102,9 +102,32 @@ public class AutoupdateUtil {
component.repaint();
}
private static Window getSelectedWindow(Window[] windows) {
for (Window window : windows) {
if (window.isActive()) {
return window;
} else {
Window[] ownedWindows = window.getOwnedWindows();
if (ownedWindows != null) {
return getSelectedWindow(ownedWindows);
}
}
}
return null;
}
public static void assertAwtThread() {
if (!SwingUtilities.isEventDispatchThread())
throw new IllegalStateException("Not on AWT thread but " + Thread.currentThread().getName());
if (!SwingUtilities.isEventDispatchThread()) {
Exception e = new IllegalStateException("Not on AWT thread but " + Thread.currentThread().getName());
StringBuilder trace = new StringBuilder(e + "\n");
for(StackTraceElement element : e.getStackTrace())
trace.append(element.toString()).append("\n");
SwingUtilities.invokeLater(() -> {
Window w = getSelectedWindow(Window.getWindows());
JOptionPane.showMessageDialog(w, trace, "Error", JOptionPane.ERROR_MESSAGE);
});
}
}
public static boolean hasExistingFile(String zipFileName, long completeFileSize, long lastModified) {