in src/main/resources/patch/Agreement.java [69:104]
private static <T extends Throwable> void runInEdtAndWait(@NotNull ThrowableRunnable<T> runnable) throws T {
final Application app = ApplicationManager.getApplication();
if (app != null ? app.isDispatchThread()
: SwingUtilities.isEventDispatchThread()) {
// reduce stack trace
runnable.run();
return;
}
final Ref<T> exception = new Ref<>();
final Runnable r = () -> {
try {
runnable.run();
}
catch (Throwable e) {
//noinspection unchecked
exception.set((T)e);
}
};
if (app != null) {
app.invokeAndWait(r);
}
else {
try {
SwingUtilities.invokeAndWait(r);
}
catch (InterruptedException | InvocationTargetException e) {
throw new RuntimeException(e); // must not happen
}
}
if (!exception.isNull()) {
throw exception.get();
}
}